Merge remote-tracking branch 'origin/develop' into MXS-329-develop-20151111
# Conflicts: # server/core/CMakeLists.txt # server/core/buffer.c # server/core/service.c # server/modules/filter/tee.c # server/modules/monitor/mysql_mon.c # server/modules/routing/binlog/blr.c # server/modules/routing/binlog/blr_slave.c # server/modules/routing/debugcmd.c # server/modules/routing/readwritesplit/readwritesplit.c # utils/skygw_utils.cc - resolved.
This commit is contained in:
@ -16,6 +16,9 @@
|
||||
* Copyright MariaDB Corporation Ab 2013-2014
|
||||
*/
|
||||
|
||||
#ifndef PCRE2_CODE_UNIT_WIDTH
|
||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -31,6 +34,7 @@
|
||||
#include "skygw_utils.h"
|
||||
#include <atomic.h>
|
||||
#include <random_jkiss.h>
|
||||
#include <pcre2.h>
|
||||
|
||||
#if defined(MLIST)
|
||||
|
||||
@ -2118,6 +2122,63 @@ retblock:
|
||||
return newstr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace everything inside single or double quotes with question marks.
|
||||
* @param str String to modify
|
||||
* @return Pointer to new modified string or NULL if memory allocation failed
|
||||
*/
|
||||
char* replace_quoted(const char* str)
|
||||
{
|
||||
PCRE2_SIZE erroffset;
|
||||
int errcore;
|
||||
static const PCRE2_SPTR pattern = (PCRE2_SPTR) "(['\"])[^'\"]+(['\"])";
|
||||
static const PCRE2_SPTR replace = (PCRE2_SPTR) "$1?$2";
|
||||
pcre2_code* re;
|
||||
pcre2_match_data* mdata;
|
||||
int orig_len = strlen(str);
|
||||
size_t len = strlen(str);
|
||||
char* output;
|
||||
|
||||
if ((output = (char*) malloc(len * sizeof(char))))
|
||||
{
|
||||
/** TODO: Consider moving pattern compilation to some init function. */
|
||||
if ((re = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED,
|
||||
0, &errcore, &erroffset, NULL)))
|
||||
{
|
||||
if ((mdata = pcre2_match_data_create_from_pattern(re, NULL)))
|
||||
{
|
||||
while (pcre2_substitute(re, (PCRE2_SPTR) str, orig_len, 0,
|
||||
PCRE2_SUBSTITUTE_GLOBAL, mdata, NULL,
|
||||
replace, PCRE2_ZERO_TERMINATED,
|
||||
(PCRE2_UCHAR8*) output, &len) == PCRE2_ERROR_NOMEMORY)
|
||||
{
|
||||
char* tmp = (char*) realloc(output, len *= 2);
|
||||
if (tmp == NULL)
|
||||
{
|
||||
free(output);
|
||||
output = NULL;
|
||||
break;
|
||||
}
|
||||
output = tmp;
|
||||
}
|
||||
pcre2_match_data_free(mdata);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(output);
|
||||
output = NULL;
|
||||
}
|
||||
pcre2_code_free(re);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(output);
|
||||
output = NULL;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the number of decimal numbers from a size_t value.
|
||||
*
|
||||
|
Reference in New Issue
Block a user