Move transforming function to common place

Move function for converting a MySQL account string to an
equivalent PCRE one, from Cache's rules.cc to mysql_utils.
This commit is contained in:
Johan Wikman
2016-12-29 10:57:35 +02:00
parent c6e155cf2b
commit 997bec868f
3 changed files with 86 additions and 75 deletions

View File

@ -235,3 +235,53 @@ bool mxs_mysql_trim_quotes(char *s)
return dequoted;
}
mxs_mysql_account_kind_t mxs_mysql_account_to_pcre(char *pcre,
const char *mysql,
mxs_pcre_quote_approach_t approach)
{
mxs_mysql_account_kind_t rv = MXS_MYSQL_ACCOUNT_WITHOUT_WILDCARD;
while (*mysql)
{
switch (*mysql)
{
case '%':
if (approach == MXS_PCRE_QUOTE_QUERY)
{
*pcre = '.';
pcre++;
*pcre = '*';
}
rv = MXS_MYSQL_ACCOUNT_WITH_WILDCARD;
break;
case '\'':
case '^':
case '.':
case '$':
case '|':
case '(':
case ')':
case '[':
case ']':
case '*':
case '+':
case '?':
case '{':
case '}':
*pcre++ = '\\';
// Flowthrough
default:
*pcre = *mysql;
}
++pcre;
++mysql;
}
*pcre = 0;
return rv;
}