Merge branch 'develop' into firewall
Conflicts: server/modules/filter/test/harness.h server/modules/filter/test/harness_common.c
This commit is contained in:
@ -69,7 +69,7 @@
|
||||
#include <ini.h>
|
||||
#include <hint.h>
|
||||
#include <modutil.h>
|
||||
#include <errno.h>
|
||||
#include <mysql_client_server_protocol.h>
|
||||
/**
|
||||
* A single name-value pair and a link to the next item in the
|
||||
* configuration.
|
||||
@ -118,7 +118,6 @@ typedef struct
|
||||
int running;
|
||||
int verbose; /**Whether to print to stdout*/
|
||||
int infile; /**A file where the queries are loaded from*/
|
||||
int expected;
|
||||
int error;
|
||||
char* mod_dir; /**Module directory absolute path*/
|
||||
char* infile_name;
|
||||
@ -127,6 +126,7 @@ typedef struct
|
||||
FILTERCHAIN* head; /**The head of the filter chain*/
|
||||
FILTERCHAIN* tail; /**The tail of the filter chain*/
|
||||
GWBUF** buffer; /**Buffers that are fed to the filter chain*/
|
||||
SESSION* session;
|
||||
int buffer_count;
|
||||
int session_count;
|
||||
DOWNSTREAM dummyrouter; /**Dummy downstream router for data extraction*/
|
||||
@ -174,7 +174,7 @@ typedef packet_t PACKET;
|
||||
/**
|
||||
* Initialize the static instance.
|
||||
*/
|
||||
int harness_init(int argc,char** argv,HARNESS_INSTANCE** inst);
|
||||
int harness_init(int argc,char** argv);
|
||||
|
||||
/**
|
||||
* Frees all the query buffers
|
||||
@ -361,14 +361,4 @@ GWBUF* gen_packet(PACKET pkt);
|
||||
*/
|
||||
int process_opts(int argc, char** argv);
|
||||
|
||||
/**
|
||||
* Compares the contents of two files.
|
||||
* This function resets the offsets of the file descriptors and leaves them in an
|
||||
* undefined state.
|
||||
* @param a The first file
|
||||
* @param b The second file
|
||||
* @return 0 if the files do not differ and 1 if they do or an error occurred.
|
||||
*/
|
||||
int compare_files(int a, int b);
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,6 +1,12 @@
|
||||
#include <harness.h>
|
||||
|
||||
int harness_init(int argc, char** argv, HARNESS_INSTANCE** inst){
|
||||
int dcbfun(struct dcb* dcb, GWBUF * buffer)
|
||||
{
|
||||
printf("Data was written to client DCB.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int harness_init(int argc, char** argv){
|
||||
int i = 0;
|
||||
if(!(argc == 2 && strcmp(argv[1],"-h") == 0)){
|
||||
skygw_logmanager_init(0,NULL);
|
||||
@ -14,14 +20,20 @@ int harness_init(int argc, char** argv, HARNESS_INSTANCE** inst){
|
||||
return 1;
|
||||
}
|
||||
|
||||
*inst = &instance;
|
||||
instance.running = 1;
|
||||
instance.infile = -1;
|
||||
instance.outfile = -1;
|
||||
instance.expected = -1;
|
||||
instance.buff_ind = -1;
|
||||
instance.last_ind = -1;
|
||||
instance.sess_ind = -1;
|
||||
instance.session = calloc(1,sizeof(SESSION));
|
||||
MYSQL_session* mysqlsess = calloc(1,sizeof(MYSQL_session));
|
||||
DCB* dcb = calloc(1,sizeof(DCB));
|
||||
|
||||
sprintf(mysqlsess->user,"dummyuser");
|
||||
sprintf(mysqlsess->db,"dummydb");
|
||||
dcb->func.write = dcbfun;
|
||||
instance.session->client = (void*)dcb;
|
||||
|
||||
process_opts(argc,argv);
|
||||
|
||||
@ -86,17 +98,15 @@ void free_buffers()
|
||||
}
|
||||
int open_file(char* str, unsigned int write)
|
||||
{
|
||||
int mode,fd;
|
||||
int mode;
|
||||
|
||||
if(write){
|
||||
mode = O_RDWR|O_CREAT;
|
||||
}else{
|
||||
mode = O_RDONLY;
|
||||
}
|
||||
if((fd = open(str,mode,S_IRWXU|S_IRGRP|S_IXGRP|S_IXOTH)) < 0){
|
||||
printf("Error %d: %s\n",errno,strerror(errno));
|
||||
}
|
||||
return fd;
|
||||
|
||||
return open(str,mode,S_IRWXU|S_IRGRP|S_IXGRP|S_IXOTH);
|
||||
}
|
||||
|
||||
|
||||
@ -612,8 +622,6 @@ int load_filter(FILTERCHAIN* fc, CONFIG* cnf)
|
||||
{
|
||||
FILTER_PARAMETER** fparams = NULL;
|
||||
int i, paramc = -1;
|
||||
int sess_err = 0;
|
||||
int x;
|
||||
if(cnf == NULL){
|
||||
|
||||
fparams = read_params(¶mc);
|
||||
@ -678,19 +686,16 @@ int load_filter(FILTERCHAIN* fc, CONFIG* cnf)
|
||||
}
|
||||
}
|
||||
|
||||
int sess_err = 0;
|
||||
|
||||
if(cnf && fc && fc->instance){
|
||||
|
||||
|
||||
fc->filter = (FILTER*)fc->instance->createInstance(NULL,fparams);
|
||||
if(fc->filter == NULL){
|
||||
printf("Error loading filter:%s: createInstance returned NULL.\n",fc->name);
|
||||
sess_err = 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
for(i = 0;i<instance.session_count;i++){
|
||||
|
||||
if((fc->session[i] = fc->instance->newSession(fc->filter, fc->session[i])) &&
|
||||
if((fc->session[i] = fc->instance->newSession(fc->filter, instance.session)) &&
|
||||
(fc->down[i] = calloc(1,sizeof(DOWNSTREAM))) &&
|
||||
(fc->up[i] = calloc(1,sizeof(UPSTREAM)))){
|
||||
|
||||
@ -702,7 +707,7 @@ int load_filter(FILTERCHAIN* fc, CONFIG* cnf)
|
||||
fc->instance->setUpstream(fc->filter, fc->session[i], fc->up[i]);
|
||||
}else{
|
||||
skygw_log_write(LOGFILE_MESSAGE,
|
||||
"Warning: The filter %s does not support client relies.\n",fc->name);
|
||||
"Warning: The filter %s does not support client replies.\n",fc->name);
|
||||
}
|
||||
|
||||
if(fc->next && fc->next->next){
|
||||
@ -755,8 +760,8 @@ int load_filter(FILTERCHAIN* fc, CONFIG* cnf)
|
||||
}
|
||||
|
||||
}
|
||||
error:
|
||||
|
||||
|
||||
int x;
|
||||
|
||||
if(fparams){
|
||||
for(x = 0;x<paramc;x++){
|
||||
@ -872,14 +877,9 @@ void work_buffer(void* thr_num)
|
||||
index < instance.session_count &&
|
||||
instance.buff_ind < instance.buffer_count)
|
||||
{
|
||||
if(instance.head->instance->routeQuery(instance.head->filter,
|
||||
instance.head->instance->routeQuery(instance.head->filter,
|
||||
instance.head->session[index],
|
||||
instance.buffer[instance.buff_ind]) == 0){
|
||||
if(instance.outfile > 0){
|
||||
const char* msg = "Query returned 0.\n";
|
||||
write(instance.outfile,msg,strlen(msg));
|
||||
}
|
||||
}
|
||||
instance.buffer[instance.buff_ind]);
|
||||
if(instance.tail->instance->clientReply){
|
||||
instance.tail->instance->clientReply(instance.tail->filter,
|
||||
instance.tail->session[index],
|
||||
@ -943,11 +943,10 @@ GWBUF* gen_packet(PACKET pkt)
|
||||
}
|
||||
|
||||
|
||||
|
||||
int process_opts(int argc, char** argv)
|
||||
{
|
||||
int fd, buffsize = 1024;
|
||||
int rd,rdsz, rval = 0;
|
||||
int rd,rdsz, rval;
|
||||
size_t fsize;
|
||||
char *buff = calloc(buffsize,sizeof(char)), *tok = NULL;
|
||||
|
||||
@ -1000,18 +999,10 @@ int process_opts(int argc, char** argv)
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* conf_name = NULL;
|
||||
rval = 0;
|
||||
|
||||
while((rd = getopt(argc,argv,"e:m:c:i:o:s:t:d:qh")) > 0){
|
||||
while((rd = getopt(argc,argv,"m:c:i:o:s:t:d:qh")) > 0){
|
||||
switch(rd){
|
||||
|
||||
case 'e':
|
||||
instance.expected = open_file(optarg,0);
|
||||
printf("Expected output is read from: %s\n",optarg);
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
instance.outfile = open_file(optarg,1);
|
||||
printf("Output is written to: %s\n",optarg);
|
||||
@ -1076,7 +1067,6 @@ int process_opts(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if(conf_name && load_config(conf_name)){
|
||||
load_query();
|
||||
}else{
|
||||
@ -1085,30 +1075,5 @@ int process_opts(int argc, char** argv)
|
||||
free(conf_name);
|
||||
close(fd);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
int compare_files(int a,int b)
|
||||
{
|
||||
char in[4098];
|
||||
char exp[4098];
|
||||
int line = 1;
|
||||
|
||||
if(a < 1 || b < 1){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(lseek(a,0,SEEK_SET) < 0 ||
|
||||
lseek(b,0,SEEK_SET) < 0){
|
||||
return 1;
|
||||
}
|
||||
|
||||
while(fdgets(a,in,4098) && fdgets(b,exp,4098)){
|
||||
if(strcmp(in,exp)){
|
||||
printf("The files differ at line %d:\n%s\n-------------------------------------\n%s\n",line,in,exp);
|
||||
return 1;
|
||||
}
|
||||
line++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user