Use module parameters in ccrfilter and luafilter
The ccrfilter and luafilter now use the module parameters.
This commit is contained in:
@ -55,7 +55,7 @@ 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 uint64_t getCapabilities(void);
|
static uint64_t getCapabilities(void);
|
||||||
|
|
||||||
#define CCR_DEFAULT_TIME 60
|
#define CCR_DEFAULT_TIME "60"
|
||||||
|
|
||||||
typedef struct lagstats
|
typedef struct lagstats
|
||||||
{
|
{
|
||||||
@ -129,6 +129,10 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
|||||||
NULL, /* Thread init. */
|
NULL, /* Thread init. */
|
||||||
NULL, /* Thread finish. */
|
NULL, /* Thread finish. */
|
||||||
{
|
{
|
||||||
|
{"count", MXS_MODULE_PARAM_COUNT, "0"},
|
||||||
|
{"time", MXS_MODULE_PARAM_COUNT, CCR_DEFAULT_TIME},
|
||||||
|
{"match", MXS_MODULE_PARAM_STRING},
|
||||||
|
{"ignore", MXS_MODULE_PARAM_STRING},
|
||||||
{MXS_END_MODULE_PARAMS}
|
{MXS_END_MODULE_PARAMS}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -155,38 +159,14 @@ createInstance(const char *name, char **options, CONFIG_PARAMETER *params)
|
|||||||
|
|
||||||
if ((my_instance = MXS_CALLOC(1, sizeof(CCR_INSTANCE))) != NULL)
|
if ((my_instance = MXS_CALLOC(1, sizeof(CCR_INSTANCE))) != NULL)
|
||||||
{
|
{
|
||||||
my_instance->count = 0;
|
my_instance->count = config_get_integer(params, "count");
|
||||||
my_instance->time = CCR_DEFAULT_TIME;
|
my_instance->time = config_get_integer(params, "count");
|
||||||
my_instance->stats.n_add_count = 0;
|
my_instance->stats.n_add_count = 0;
|
||||||
my_instance->stats.n_add_time = 0;
|
my_instance->stats.n_add_time = 0;
|
||||||
my_instance->stats.n_modified = 0;
|
my_instance->stats.n_modified = 0;
|
||||||
my_instance->match = NULL;
|
my_instance->match = NULL;
|
||||||
my_instance->nomatch = NULL;
|
my_instance->nomatch = NULL;
|
||||||
|
|
||||||
for (const CONFIG_PARAMETER *p = params; p; p = p->next)
|
|
||||||
{
|
|
||||||
if (!strcmp(p->name, "count"))
|
|
||||||
{
|
|
||||||
my_instance->count = atoi(p->value);
|
|
||||||
}
|
|
||||||
else if (!strcmp(p->name, "time"))
|
|
||||||
{
|
|
||||||
my_instance->time = atoi(p->value);
|
|
||||||
}
|
|
||||||
else if (!strcmp(p->name, "match"))
|
|
||||||
{
|
|
||||||
my_instance->match = MXS_STRDUP_A(p->value);
|
|
||||||
}
|
|
||||||
else if (!strcmp(p->name, "ignore"))
|
|
||||||
{
|
|
||||||
my_instance->nomatch = MXS_STRDUP_A(p->value);
|
|
||||||
}
|
|
||||||
else if (!filter_standard_parameter(p->name))
|
|
||||||
{
|
|
||||||
MXS_ERROR("ccrfilter: Unexpected parameter '%s'.\n", p->name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options)
|
if (options)
|
||||||
{
|
{
|
||||||
for (i = 0; options[i]; i++)
|
for (i = 0; options[i]; i++)
|
||||||
@ -210,7 +190,9 @@ createInstance(const char *name, char **options, CONFIG_PARAMETER *params)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (my_instance->match)
|
const char *match = config_get_string(params, "match");
|
||||||
|
|
||||||
|
if (*match && (my_instance->match = MXS_STRDUP(match)))
|
||||||
{
|
{
|
||||||
if (regcomp(&my_instance->re, my_instance->match, cflags))
|
if (regcomp(&my_instance->re, my_instance->match, cflags))
|
||||||
{
|
{
|
||||||
@ -218,7 +200,9 @@ createInstance(const char *name, char **options, CONFIG_PARAMETER *params)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (my_instance->nomatch)
|
const char *ignore = config_get_string(params, "ignore");
|
||||||
|
|
||||||
|
if (*ignore && (my_instance->nomatch = MXS_STRDUP(ignore)))
|
||||||
{
|
{
|
||||||
if (regcomp(&my_instance->nore, my_instance->nomatch, cflags))
|
if (regcomp(&my_instance->nore, my_instance->nomatch, cflags))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -102,6 +102,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
|
|||||||
NULL, /* Thread init. */
|
NULL, /* Thread init. */
|
||||||
NULL, /* Thread finish. */
|
NULL, /* Thread finish. */
|
||||||
{
|
{
|
||||||
|
{"global_script", MXS_MODULE_PARAM_PATH, NULL, MXS_MODULE_OPT_PATH_R_OK},
|
||||||
|
{"session_script", MXS_MODULE_PARAM_PATH, NULL, MXS_MODULE_OPT_PATH_R_OK},
|
||||||
{MXS_END_MODULE_PARAMS}
|
{MXS_END_MODULE_PARAMS}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -208,24 +210,11 @@ createInstance(const char *name, char **options, CONFIG_PARAMETER *params)
|
|||||||
|
|
||||||
spinlock_init(&my_instance->lock);
|
spinlock_init(&my_instance->lock);
|
||||||
|
|
||||||
for (CONFIG_PARAMETER *p = p; p && !error; p = p->next)
|
const char *global_script = config_get_string(params, "global_script");
|
||||||
{
|
const char *session_script = config_get_string(params, "session_script");
|
||||||
if (strcmp(p->name, "global_script") == 0)
|
|
||||||
{
|
|
||||||
error = (my_instance->global_script = MXS_STRDUP(p->value)) == NULL;
|
|
||||||
}
|
|
||||||
else if (strcmp(p->name, "session_script") == 0)
|
|
||||||
{
|
|
||||||
error = (my_instance->session_script = MXS_STRDUP(p->value)) == NULL;
|
|
||||||
}
|
|
||||||
else if (!filter_standard_parameter(p->name))
|
|
||||||
{
|
|
||||||
MXS_ERROR("Unexpected parameter '%s'", p->name);
|
|
||||||
error = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error)
|
if ((*global_script && (my_instance->global_script = MXS_STRDUP(global_script)) == NULL) ||
|
||||||
|
(*session_script && (my_instance->session_script = MXS_STRDUP(session_script)) == NULL))
|
||||||
{
|
{
|
||||||
MXS_FREE(my_instance->global_script);
|
MXS_FREE(my_instance->global_script);
|
||||||
MXS_FREE(my_instance->session_script);
|
MXS_FREE(my_instance->session_script);
|
||||||
|
|||||||
Reference in New Issue
Block a user