Merge branch 'develop' into firewall
This commit is contained in:
@ -202,7 +202,7 @@ int i;
|
||||
free(my_instance->filebase);
|
||||
my_instance->filebase = NULL;
|
||||
}
|
||||
my_instance->source = strdup(params[i]->value);
|
||||
my_instance->filebase = strdup(params[i]->value);
|
||||
}
|
||||
else if (!filter_standard_parameter(params[i]->name))
|
||||
{
|
||||
@ -408,7 +408,7 @@ struct timeval tv;
|
||||
{
|
||||
queue = gwbuf_make_contiguous(queue);
|
||||
}
|
||||
if (modutil_extract_SQL(queue, &ptr, &length) != 0)
|
||||
if ((ptr = modutil_get_SQL(queue)) != NULL)
|
||||
{
|
||||
if ((my_instance->match == NULL ||
|
||||
regexec(&my_instance->re, ptr, 0, NULL, 0) == 0) &&
|
||||
@ -424,6 +424,7 @@ struct timeval tv;
|
||||
fwrite(ptr, sizeof(char), length, my_session->fp);
|
||||
fwrite("\n", sizeof(char), 1, my_session->fp);
|
||||
}
|
||||
free(ptr);
|
||||
}
|
||||
}
|
||||
/* Pass the query downstream */
|
||||
|
||||
@ -60,7 +60,7 @@ static void setDownstream(FILTER *instance, void *fsession, DOWNSTREAM *downstre
|
||||
static int routeQuery(FILTER *instance, void *fsession, GWBUF *queue);
|
||||
static void diagnostic(FILTER *instance, void *fsession, DCB *dcb);
|
||||
|
||||
static char *regex_replace(char *sql, int length, regex_t *re, char *replace);
|
||||
static char *regex_replace(char *sql, regex_t *re, char *replace);
|
||||
|
||||
static FILTER_OBJECT MyObject = {
|
||||
createInstance,
|
||||
@ -302,7 +302,6 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
||||
REGEX_INSTANCE *my_instance = (REGEX_INSTANCE *)instance;
|
||||
REGEX_SESSION *my_session = (REGEX_SESSION *)session;
|
||||
char *sql, *newsql;
|
||||
int length;
|
||||
|
||||
if (modutil_is_SQL(queue))
|
||||
{
|
||||
@ -310,18 +309,21 @@ int length;
|
||||
{
|
||||
queue = gwbuf_make_contiguous(queue);
|
||||
}
|
||||
modutil_extract_SQL(queue, &sql, &length);
|
||||
newsql = regex_replace(sql, length, &my_instance->re,
|
||||
my_instance->replace);
|
||||
if (newsql)
|
||||
if ((sql = modutil_get_SQL(queue)) != NULL)
|
||||
{
|
||||
queue = modutil_replace_SQL(queue, newsql);
|
||||
queue = gwbuf_make_contiguous(queue);
|
||||
free(newsql);
|
||||
my_session->replacements++;
|
||||
newsql = regex_replace(sql, &my_instance->re,
|
||||
my_instance->replace);
|
||||
if (newsql)
|
||||
{
|
||||
queue = modutil_replace_SQL(queue, newsql);
|
||||
queue = gwbuf_make_contiguous(queue);
|
||||
free(newsql);
|
||||
my_session->replacements++;
|
||||
}
|
||||
else
|
||||
my_session->no_change++;
|
||||
free(sql);
|
||||
}
|
||||
else
|
||||
my_session->no_change++;
|
||||
|
||||
}
|
||||
return my_session->down.routeQuery(my_session->down.instance,
|
||||
@ -368,26 +370,23 @@ REGEX_SESSION *my_session = (REGEX_SESSION *)fsession;
|
||||
* Perform a regular expression match and subsititution on the SQL
|
||||
*
|
||||
* @param sql The original SQL text
|
||||
* @param length The length of the SQL text
|
||||
* @param re The compiled regular expression
|
||||
* @param replace The replacement text
|
||||
* @return The replaced text or NULL if no replacement was done.
|
||||
*/
|
||||
static char *
|
||||
regex_replace(char *sql, int length, regex_t *re, char *replace)
|
||||
regex_replace(char *sql, regex_t *re, char *replace)
|
||||
{
|
||||
char *orig, *result, *ptr;
|
||||
int i, res_size, res_length, rep_length;
|
||||
int last_match;
|
||||
int last_match, length;
|
||||
regmatch_t match[10];
|
||||
|
||||
orig = strndup(sql, length);
|
||||
if (regexec(re, orig, 10, match, 0))
|
||||
if (regexec(re, sql, 10, match, 0))
|
||||
{
|
||||
free(orig);
|
||||
return NULL;
|
||||
}
|
||||
free(orig);
|
||||
length = strlen(sql);
|
||||
|
||||
res_size = 2 * length;
|
||||
result = (char *)malloc(res_size);
|
||||
|
||||
@ -403,16 +403,19 @@ GWBUF *clone = NULL;
|
||||
if (my_session->residual < 0)
|
||||
my_session->residual = 0;
|
||||
}
|
||||
else if (my_session->active &&
|
||||
modutil_MySQL_Query(queue, &ptr, &length, &residual))
|
||||
else if (my_session->active && (ptr = modutil_get_SQL(queue) != NULL))
|
||||
{
|
||||
if ((my_instance->match == NULL ||
|
||||
regexec(&my_instance->re, ptr, 0, NULL, 0) == 0) &&
|
||||
(my_instance->nomatch == NULL ||
|
||||
regexec(&my_instance->nore,ptr,0,NULL, 0) != 0))
|
||||
{
|
||||
char *dummy;
|
||||
|
||||
modutil_MySQL_Query(queue, &dummy, &length, &residual);
|
||||
clone = gwbuf_clone(queue);
|
||||
my_session->residual = residual;
|
||||
free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -137,8 +137,8 @@ FILTER_PARAMETER** read_params(int* paramc)
|
||||
do_read = 0;
|
||||
}
|
||||
}
|
||||
FILTER_PARAMETER** params;
|
||||
if((params = malloc(sizeof(FILTER_PARAMETER*)*(pc+1)))!=NULL){
|
||||
FILTER_PARAMETER** params = NULL;
|
||||
if((params = malloc(sizeof(FILTER_PARAMETER*)*(pc+1))) != NULL){
|
||||
for(i = 0;i<pc;i++){
|
||||
params[i] = malloc(sizeof(FILTER_PARAMETER));
|
||||
if(params[i]){
|
||||
@ -147,10 +147,10 @@ FILTER_PARAMETER** read_params(int* paramc)
|
||||
}
|
||||
free(names[i]);
|
||||
free(values[i]);
|
||||
}
|
||||
}
|
||||
params[pc] = NULL;
|
||||
*paramc = pc;
|
||||
}
|
||||
params[pc] = NULL;
|
||||
*paramc = pc;
|
||||
return params;
|
||||
}
|
||||
|
||||
@ -303,18 +303,19 @@ int load_query()
|
||||
int i, qcount = 0, qbuff_sz = 10, rval = 0;
|
||||
int offset = 0;
|
||||
unsigned int qlen = 0;
|
||||
|
||||
if((buffer = malloc(4092*sizeof(char))) == NULL){
|
||||
buffer = (char*)calloc(4092,sizeof(char));
|
||||
if(buffer == NULL){
|
||||
printf("Error: cannot allocate enough memory.\n");
|
||||
skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate enough memory.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if((query_list = calloc(qbuff_sz,sizeof(char*))) == NULL){
|
||||
query_list = calloc(qbuff_sz,sizeof(char*));
|
||||
if(query_list == NULL){
|
||||
printf("Error: cannot allocate enough memory.\n");
|
||||
skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate enough memory.\n");
|
||||
rval = 1;
|
||||
goto retblock;
|
||||
free(buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -924,8 +925,9 @@ GWBUF* gen_packet(PACKET pkt)
|
||||
|
||||
int process_opts(int argc, char** argv)
|
||||
{
|
||||
int fd = open_file("harness.cnf",1), buffsize = 1024;
|
||||
int rd,fsize,rdsz;
|
||||
unsigned int fd = open_file("harness.cnf",1), buffsize = 1024;
|
||||
int rd,rdsz;
|
||||
unsigned int fsize;
|
||||
char *buff = calloc(buffsize,sizeof(char)), *tok = NULL;
|
||||
|
||||
/**Parse 'harness.cnf' file*/
|
||||
@ -953,6 +955,7 @@ int process_opts(int argc, char** argv)
|
||||
instance.verbose = 1;
|
||||
|
||||
if(argc < 2){
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
char* conf_name = NULL;
|
||||
@ -970,6 +973,9 @@ int process_opts(int argc, char** argv)
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
if(conf_name){
|
||||
free(conf_name);
|
||||
}
|
||||
conf_name = strdup(optarg);
|
||||
break;
|
||||
|
||||
|
||||
@ -453,7 +453,6 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
||||
TOPN_INSTANCE *my_instance = (TOPN_INSTANCE *)instance;
|
||||
TOPN_SESSION *my_session = (TOPN_SESSION *)session;
|
||||
char *ptr;
|
||||
int length;
|
||||
|
||||
if (my_session->active)
|
||||
{
|
||||
@ -461,7 +460,7 @@ int length;
|
||||
{
|
||||
queue = gwbuf_make_contiguous(queue);
|
||||
}
|
||||
if (modutil_extract_SQL(queue, &ptr, &length) != 0)
|
||||
if ((ptr = modutil_get_SQL(queue)) != NULL)
|
||||
{
|
||||
if ((my_instance->match == NULL ||
|
||||
regexec(&my_instance->re, ptr, 0, NULL, 0) == 0) &&
|
||||
@ -472,7 +471,11 @@ int length;
|
||||
if (my_session->current)
|
||||
free(my_session->current);
|
||||
gettimeofday(&my_session->start, NULL);
|
||||
my_session->current = strndup(ptr, length);
|
||||
my_session->current = ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user