Bug 571 - regression in replacement code
This commit is contained in:
@ -60,7 +60,7 @@ static void setDownstream(FILTER *instance, void *fsession, DOWNSTREAM *downstre
|
|||||||
static int routeQuery(FILTER *instance, void *fsession, GWBUF *queue);
|
static int routeQuery(FILTER *instance, void *fsession, GWBUF *queue);
|
||||||
static void diagnostic(FILTER *instance, void *fsession, DCB *dcb);
|
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 = {
|
static FILTER_OBJECT MyObject = {
|
||||||
createInstance,
|
createInstance,
|
||||||
@ -302,7 +302,6 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
|||||||
REGEX_INSTANCE *my_instance = (REGEX_INSTANCE *)instance;
|
REGEX_INSTANCE *my_instance = (REGEX_INSTANCE *)instance;
|
||||||
REGEX_SESSION *my_session = (REGEX_SESSION *)session;
|
REGEX_SESSION *my_session = (REGEX_SESSION *)session;
|
||||||
char *sql, *newsql;
|
char *sql, *newsql;
|
||||||
int length;
|
|
||||||
|
|
||||||
if (modutil_is_SQL(queue))
|
if (modutil_is_SQL(queue))
|
||||||
{
|
{
|
||||||
@ -312,7 +311,7 @@ int length;
|
|||||||
}
|
}
|
||||||
if ((sql = modutil_get_SQL(queue)) != NULL)
|
if ((sql = modutil_get_SQL(queue)) != NULL)
|
||||||
{
|
{
|
||||||
newsql = regex_replace(sql, length, &my_instance->re,
|
newsql = regex_replace(sql, &my_instance->re,
|
||||||
my_instance->replace);
|
my_instance->replace);
|
||||||
if (newsql)
|
if (newsql)
|
||||||
{
|
{
|
||||||
@ -371,26 +370,23 @@ REGEX_SESSION *my_session = (REGEX_SESSION *)fsession;
|
|||||||
* Perform a regular expression match and subsititution on the SQL
|
* Perform a regular expression match and subsititution on the SQL
|
||||||
*
|
*
|
||||||
* @param sql The original SQL text
|
* @param sql The original SQL text
|
||||||
* @param length The length of the SQL text
|
|
||||||
* @param re The compiled regular expression
|
* @param re The compiled regular expression
|
||||||
* @param replace The replacement text
|
* @param replace The replacement text
|
||||||
* @return The replaced text or NULL if no replacement was done.
|
* @return The replaced text or NULL if no replacement was done.
|
||||||
*/
|
*/
|
||||||
static char *
|
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;
|
char *orig, *result, *ptr;
|
||||||
int i, res_size, res_length, rep_length;
|
int i, res_size, res_length, rep_length;
|
||||||
int last_match;
|
int last_match, length;
|
||||||
regmatch_t match[10];
|
regmatch_t match[10];
|
||||||
|
|
||||||
orig = strndup(sql, length);
|
if (regexec(re, sql, 10, match, 0))
|
||||||
if (regexec(re, orig, 10, match, 0))
|
|
||||||
{
|
{
|
||||||
free(orig);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
free(orig);
|
length = strlen(sql);
|
||||||
|
|
||||||
res_size = 2 * length;
|
res_size = 2 * length;
|
||||||
result = (char *)malloc(res_size);
|
result = (char *)malloc(res_size);
|
||||||
|
Reference in New Issue
Block a user