Rename FILTER_DEF to MXS_FILTER_DEF

Provide functions that allows the actual definition of MXS_FILTER_DEF
to be made private.
This commit is contained in:
Johan Wikman
2017-01-13 14:30:11 +02:00
parent affec5e388
commit 265e5c0593
14 changed files with 101 additions and 241 deletions

View File

@ -92,7 +92,7 @@ typedef struct mxs_filter_object
* This is basically the link between a plugin to load and the * This is basically the link between a plugin to load and the
* optons to pass to that plugin. * optons to pass to that plugin.
*/ */
typedef struct filter_def typedef struct mxs_filter_def
{ {
char *name; /**< The Filter name */ char *name; /**< The Filter name */
char *module; /**< The module to load */ char *module; /**< The module to load */
@ -101,13 +101,37 @@ typedef struct filter_def
MXS_FILTER* filter; /**< The runtime filter */ MXS_FILTER* filter; /**< The runtime filter */
MXS_FILTER_OBJECT *obj; /**< The "MODULE_OBJECT" for the filter */ MXS_FILTER_OBJECT *obj; /**< The "MODULE_OBJECT" for the filter */
SPINLOCK spin; /**< Spinlock to protect the filter definition */ SPINLOCK spin; /**< Spinlock to protect the filter definition */
struct filter_def *next; /**< Next filter in the chain of all filters */ struct mxs_filter_def *next; /**< Next filter in the chain of all filters */
} FILTER_DEF; } MXS_FILTER_DEF;
FILTER_DEF *filter_find(const char *); /**
* Lookup a filter definition using the unique section name in
* the configuration file.
*
* @param name The name of a filter.
*
* @return A filter definition or NULL if not found.
*/
MXS_FILTER_DEF *filter_def_find(const char *name);
/**
* Get module name of a filter definition.
*
* @param filter_def A filter definition.
*
* @return The module name.
*/
const char* filter_def_get_module_name(const MXS_FILTER_DEF* filter_def);
/**
* Get the filter instance of a particular filter definition.
*
* @return A filter instance.
*/
MXS_FILTER* filter_def_get_instance(const MXS_FILTER_DEF* filter_def);
void dprintAllFilters(DCB *); void dprintAllFilters(DCB *);
void dprintFilter(DCB *, const FILTER_DEF *); void dprintFilter(DCB *, const MXS_FILTER_DEF *);
void dListFilters(DCB *); void dListFilters(DCB *);
/** /**

View File

@ -83,14 +83,14 @@ struct arg_node
modulecmd_arg_type_t type; modulecmd_arg_type_t type;
union union
{ {
char *string; char *string;
bool boolean; bool boolean;
SERVICE *service; SERVICE *service;
SERVER *server; SERVER *server;
SESSION *session; SESSION *session;
DCB *dcb; DCB *dcb;
MONITOR *monitor; MONITOR *monitor;
FILTER_DEF *filter; MXS_FILTER_DEF *filter;
} value; } value;
}; };

View File

@ -163,7 +163,7 @@ typedef struct service
* when querying them from the server. MySQL Workbench seems * when querying them from the server. MySQL Workbench seems
* to escape at least the underscore character. */ * to escape at least the underscore character. */
SERVICE_REFRESH_RATE rate_limit; /**< The refresh rate limit for users table */ SERVICE_REFRESH_RATE rate_limit; /**< The refresh rate limit for users table */
FILTER_DEF **filters; /**< Ordered list of filters */ MXS_FILTER_DEF **filters; /**< Ordered list of filters */
int n_filters; /**< Number of filters */ int n_filters; /**< Number of filters */
long conn_idle_timeout; /**< Session timeout in seconds */ long conn_idle_timeout; /**< Session timeout in seconds */
char *weightby; /**< Service weighting parameter name */ char *weightby; /**< Service weighting parameter name */

View File

@ -45,7 +45,7 @@ MXS_BEGIN_DECLS
struct dcb; struct dcb;
struct service; struct service;
struct filter_def; struct mxs_filter_def;
struct server; struct server;
/** /**
@ -132,7 +132,7 @@ typedef struct mxs_upstream
*/ */
typedef struct typedef struct
{ {
struct filter_def *filter; struct mxs_filter_def *filter;
void *instance; void *instance;
void *session; void *session;
} SESSION_FILTER; } SESSION_FILTER;

View File

@ -34,9 +34,9 @@
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
static SPINLOCK filter_spin = SPINLOCK_INIT; /**< Protects the list of all filters */ static SPINLOCK filter_spin = SPINLOCK_INIT; /**< Protects the list of all filters */
static FILTER_DEF *allFilters = NULL; /**< The list of all filters */ static MXS_FILTER_DEF *allFilters = NULL; /**< The list of all filters */
static void filter_free_parameters(FILTER_DEF *filter); static void filter_free_parameters(MXS_FILTER_DEF *filter);
/** /**
* Allocate a new filter within MaxScale * Allocate a new filter within MaxScale
@ -47,13 +47,13 @@ static void filter_free_parameters(FILTER_DEF *filter);
* *
* @return The newly created filter or NULL if an error occured * @return The newly created filter or NULL if an error occured
*/ */
FILTER_DEF * MXS_FILTER_DEF *
filter_alloc(const char *name, const char *module) filter_alloc(const char *name, const char *module)
{ {
char* my_name = MXS_STRDUP(name); char* my_name = MXS_STRDUP(name);
char* my_module = MXS_STRDUP(module); char* my_module = MXS_STRDUP(module);
FILTER_DEF *filter = (FILTER_DEF *)MXS_MALLOC(sizeof(FILTER_DEF)); MXS_FILTER_DEF *filter = (MXS_FILTER_DEF *)MXS_MALLOC(sizeof(MXS_FILTER_DEF));
if (!my_name || !my_module || !filter) if (!my_name || !my_module || !filter)
{ {
@ -87,9 +87,9 @@ filter_alloc(const char *name, const char *module)
* @return Returns true if the server was freed * @return Returns true if the server was freed
*/ */
void void
filter_free(FILTER_DEF *filter) filter_free(MXS_FILTER_DEF *filter)
{ {
FILTER_DEF *ptr; MXS_FILTER_DEF *ptr;
if (filter) if (filter)
{ {
@ -132,17 +132,10 @@ filter_free(FILTER_DEF *filter)
} }
} }
/** MXS_FILTER_DEF *
* Find an existing filter using the unique section name in filter_def_find(const char *name)
* configuration file
*
* @param name The filter name
* @return The server or NULL if not found
*/
FILTER_DEF *
filter_find(const char *name)
{ {
FILTER_DEF *filter; MXS_FILTER_DEF *filter;
spinlock_acquire(&filter_spin); spinlock_acquire(&filter_spin);
filter = allFilters; filter = allFilters;
@ -158,6 +151,16 @@ filter_find(const char *name)
return filter; return filter;
} }
const char* filter_def_get_module_name(const MXS_FILTER_DEF* filter_def)
{
return filter_def->module;
}
MXS_FILTER* filter_def_get_instance(const MXS_FILTER_DEF* filter_def)
{
return filter_def->filter;
}
/** /**
* Check a parameter to see if it is a standard filter parameter * Check a parameter to see if it is a standard filter parameter
* *
@ -182,7 +185,7 @@ filter_standard_parameter(const char *name)
void void
dprintAllFilters(DCB *dcb) dprintAllFilters(DCB *dcb)
{ {
FILTER_DEF *ptr; MXS_FILTER_DEF *ptr;
int i; int i;
spinlock_acquire(&filter_spin); spinlock_acquire(&filter_spin);
@ -220,7 +223,7 @@ dprintAllFilters(DCB *dcb)
* to display all active filters in MaxScale * to display all active filters in MaxScale
*/ */
void void
dprintFilter(DCB *dcb, const FILTER_DEF *filter) dprintFilter(DCB *dcb, const MXS_FILTER_DEF *filter)
{ {
int i; int i;
@ -248,7 +251,7 @@ dprintFilter(DCB *dcb, const FILTER_DEF *filter)
void void
dListFilters(DCB *dcb) dListFilters(DCB *dcb)
{ {
FILTER_DEF *ptr; MXS_FILTER_DEF *ptr;
int i; int i;
spinlock_acquire(&filter_spin); spinlock_acquire(&filter_spin);
@ -287,7 +290,7 @@ dListFilters(DCB *dcb)
* @param option The option string * @param option The option string
*/ */
void void
filter_add_option(FILTER_DEF *filter, const char *option) filter_add_option(MXS_FILTER_DEF *filter, const char *option)
{ {
int i; int i;
@ -323,7 +326,7 @@ filter_add_option(FILTER_DEF *filter, const char *option)
* @param value The parameter value * @param value The parameter value
*/ */
void void
filter_add_parameter(FILTER_DEF *filter, const char *name, const char *value) filter_add_parameter(MXS_FILTER_DEF *filter, const char *name, const char *value)
{ {
CONFIG_CONTEXT ctx = {.object = ""}; CONFIG_CONTEXT ctx = {.object = ""};
@ -336,7 +339,7 @@ filter_add_parameter(FILTER_DEF *filter, const char *name, const char *value)
* Free filter parameters * Free filter parameters
* @param filter Filter whose parameters are to be freed * @param filter Filter whose parameters are to be freed
*/ */
static void filter_free_parameters(FILTER_DEF *filter) static void filter_free_parameters(MXS_FILTER_DEF *filter)
{ {
config_parameter_free(filter->parameters); config_parameter_free(filter->parameters);
} }
@ -346,7 +349,7 @@ static void filter_free_parameters(FILTER_DEF *filter)
* @param filter Filter definition * @param filter Filter definition
* @return True if module was successfully loaded, false if an error occurred * @return True if module was successfully loaded, false if an error occurred
*/ */
bool filter_load(FILTER_DEF* filter) bool filter_load(MXS_FILTER_DEF* filter)
{ {
bool rval = false; bool rval = false;
if (filter) if (filter)
@ -400,7 +403,7 @@ bool filter_load(FILTER_DEF* filter)
* if the filter could not be created * if the filter could not be created
*/ */
MXS_DOWNSTREAM * MXS_DOWNSTREAM *
filter_apply(FILTER_DEF *filter, SESSION *session, MXS_DOWNSTREAM *downstream) filter_apply(MXS_FILTER_DEF *filter, SESSION *session, MXS_DOWNSTREAM *downstream)
{ {
MXS_DOWNSTREAM *me; MXS_DOWNSTREAM *me;
@ -435,7 +438,7 @@ filter_apply(FILTER_DEF *filter, SESSION *session, MXS_DOWNSTREAM *downstream)
* @return The upstream component for the next filter * @return The upstream component for the next filter
*/ */
MXS_UPSTREAM * MXS_UPSTREAM *
filter_upstream(FILTER_DEF *filter, void *fsession, MXS_UPSTREAM *upstream) filter_upstream(MXS_FILTER_DEF *filter, void *fsession, MXS_UPSTREAM *upstream)
{ {
MXS_UPSTREAM *me = NULL; MXS_UPSTREAM *me = NULL;

View File

@ -20,13 +20,13 @@
MXS_BEGIN_DECLS MXS_BEGIN_DECLS
void filter_add_option(FILTER_DEF *filter_def, const char *option); void filter_add_option(MXS_FILTER_DEF *filter_def, const char *option);
void filter_add_parameter(FILTER_DEF *filter_def, const char *name, const char *value); void filter_add_parameter(MXS_FILTER_DEF *filter_def, const char *name, const char *value);
FILTER_DEF *filter_alloc(const char *name, const char *module_name); MXS_FILTER_DEF *filter_alloc(const char *name, const char *module_name);
MXS_DOWNSTREAM *filter_apply(FILTER_DEF *filter_def, SESSION *session, MXS_DOWNSTREAM *downstream); MXS_DOWNSTREAM *filter_apply(MXS_FILTER_DEF *filter_def, SESSION *session, MXS_DOWNSTREAM *downstream);
void filter_free(FILTER_DEF *filter_def); void filter_free(MXS_FILTER_DEF *filter_def);
bool filter_load(FILTER_DEF *filter_def); bool filter_load(MXS_FILTER_DEF *filter_def);
int filter_standard_parameter(const char *name); int filter_standard_parameter(const char *name);
MXS_UPSTREAM *filter_upstream(FILTER_DEF *filter_def, void *fsession, MXS_UPSTREAM *upstream); MXS_UPSTREAM *filter_upstream(MXS_FILTER_DEF *filter_def, void *fsession, MXS_UPSTREAM *upstream);
MXS_END_DECLS MXS_END_DECLS

View File

@ -303,7 +303,7 @@ static bool process_argument(modulecmd_arg_type_t *type, const void* value,
break; break;
case MODULECMD_ARG_FILTER: case MODULECMD_ARG_FILTER:
if ((arg->value.filter = filter_find((char*)value))) if ((arg->value.filter = filter_def_find((char*)value)))
{ {
arg->type.type = MODULECMD_ARG_FILTER; arg->type.type = MODULECMD_ARG_FILTER;
rval = true; rval = true;

View File

@ -1205,13 +1205,13 @@ void serviceSetRetryOnFailure(SERVICE *service, char* value)
bool bool
serviceSetFilters(SERVICE *service, char *filters) serviceSetFilters(SERVICE *service, char *filters)
{ {
FILTER_DEF **flist; MXS_FILTER_DEF **flist;
char *ptr, *brkt; char *ptr, *brkt;
int n = 0; int n = 0;
bool rval = true; bool rval = true;
uint64_t capabilities = 0; uint64_t capabilities = 0;
if ((flist = (FILTER_DEF **) MXS_MALLOC(sizeof(FILTER_DEF *))) == NULL) if ((flist = (MXS_FILTER_DEF **) MXS_MALLOC(sizeof(MXS_FILTER_DEF *))) == NULL)
{ {
return false; return false;
} }
@ -1219,9 +1219,9 @@ serviceSetFilters(SERVICE *service, char *filters)
while (ptr) while (ptr)
{ {
n++; n++;
FILTER_DEF **tmp; MXS_FILTER_DEF **tmp;
if ((tmp = (FILTER_DEF **) MXS_REALLOC(flist, if ((tmp = (MXS_FILTER_DEF **) MXS_REALLOC(flist,
(n + 1) * sizeof(FILTER_DEF *))) == NULL) (n + 1) * sizeof(MXS_FILTER_DEF *))) == NULL)
{ {
rval = false; rval = false;
break; break;
@ -1230,7 +1230,7 @@ serviceSetFilters(SERVICE *service, char *filters)
flist = tmp; flist = tmp;
char *filter_name = trim(ptr); char *filter_name = trim(ptr);
if ((flist[n - 1] = filter_find(filter_name))) if ((flist[n - 1] = filter_def_find(filter_name)))
{ {
if (filter_load(flist[n - 1])) if (filter_load(flist[n - 1]))
{ {
@ -1852,7 +1852,7 @@ void service_destroy_instances(void)
} }
if (svc->n_filters) if (svc->n_filters)
{ {
FILTER_DEF **filters = svc->filters; MXS_FILTER_DEF **filters = svc->filters;
for (int i = 0; i < svc->n_filters; i++) for (int i = 0; i < svc->n_filters; i++)
{ {
if (filters[i]->obj->destroyInstance && filters[i]->filter) if (filters[i]->obj->destroyInstance && filters[i]->filter)

View File

@ -43,22 +43,22 @@
static int static int
test1() test1()
{ {
FILTER_DEF *f1, *f2; MXS_FILTER_DEF *f1, *f2;
if ((f1 = filter_alloc("test1", "module")) == NULL) if ((f1 = filter_alloc("test1", "module")) == NULL)
{ {
fprintf(stderr, "filter_alloc: test 1 failed.\n"); fprintf(stderr, "filter_alloc: test 1 failed.\n");
return 1; return 1;
} }
if ((f2 = filter_find("test1")) == NULL) if ((f2 = filter_def_find("test1")) == NULL)
{ {
fprintf(stderr, "filter_find: test 2 failed.\n"); fprintf(stderr, "filter_def_find: test 2 failed.\n");
return 1; return 1;
} }
filter_free(f1); filter_free(f1);
if ((f2 = filter_find("test1")) != NULL) if ((f2 = filter_def_find("test1")) != NULL)
{ {
fprintf(stderr, "filter_find: test 3 failed delete.\n"); fprintf(stderr, "filter_def_find: test 3 failed delete.\n");
return 1; return 1;
} }
@ -76,7 +76,7 @@ test1()
static int static int
test2() test2()
{ {
FILTER_DEF *f1; MXS_FILTER_DEF *f1;
if ((f1 = filter_alloc("test1", "module")) == NULL) if ((f1 = filter_alloc("test1", "module")) == NULL)
{ {
@ -100,7 +100,7 @@ test2()
static int static int
test3() test3()
{ {
FILTER_DEF *f1; MXS_FILTER_DEF *f1;
char name[40]; char name[40];
int i, n_filters = 1000; int i, n_filters = 1000;
@ -117,25 +117,25 @@ test3()
for (i = 0; i < n_filters; i++) for (i = 0; i < n_filters; i++)
{ {
sprintf(name, "filter%d", i); sprintf(name, "filter%d", i);
if ((f1 = filter_find(name)) == NULL) if ((f1 = filter_def_find(name)) == NULL)
{ {
fprintf(stderr, "filter_find: test 3 failed.\n"); fprintf(stderr, "filter_def_find: test 3 failed.\n");
return 1; return 1;
} }
} }
for (i = 0; i < n_filters; i++) for (i = 0; i < n_filters; i++)
{ {
sprintf(name, "filter%d", i); sprintf(name, "filter%d", i);
if ((f1 = filter_find(name)) == NULL) if ((f1 = filter_def_find(name)) == NULL)
{ {
fprintf(stderr, "filter_find: test 3 failed.\n"); fprintf(stderr, "filter_def_find: test 3 failed.\n");
return 1; return 1;
} }
filter_free(f1); filter_free(f1);
if ((f1 = filter_find(name)) != NULL) if ((f1 = filter_def_find(name)) != NULL)
{ {
fprintf(stderr, fprintf(stderr,
"filter_find: test 3 failed - found deleted filter.\n"); "filter_def_find: test 3 failed - found deleted filter.\n");
return 1; return 1;
} }
} }

View File

@ -91,7 +91,7 @@ bool cache_command_show(const MODULECMD_ARG* pArgs)
DCB* pDcb = pArgs->argv[0].value.dcb; DCB* pDcb = pArgs->argv[0].value.dcb;
ss_dassert(pDcb); ss_dassert(pDcb);
const FILTER_DEF* pFilterDef = pArgs->argv[1].value.filter; const MXS_FILTER_DEF* pFilterDef = pArgs->argv[1].value.filter;
ss_dassert(pFilterDef); ss_dassert(pFilterDef);
if (strcmp(pFilterDef->module, "cache") == 0) if (strcmp(pFilterDef->module, "cache") == 0)

View File

@ -683,7 +683,7 @@ TIMERANGE* split_reverse_time(TIMERANGE* tr)
bool dbfw_reload_rules(const MODULECMD_ARG *argv) bool dbfw_reload_rules(const MODULECMD_ARG *argv)
{ {
bool rval = true; bool rval = true;
FILTER_DEF *filter = argv->argv[0].value.filter; MXS_FILTER_DEF *filter = argv->argv[0].value.filter;
FW_INSTANCE *inst = (FW_INSTANCE*)filter->filter; FW_INSTANCE *inst = (FW_INSTANCE*)filter->filter;
if (modulecmd_arg_is_present(argv, 1)) if (modulecmd_arg_is_present(argv, 1))
@ -748,7 +748,7 @@ bool dbfw_reload_rules(const MODULECMD_ARG *argv)
bool dbfw_show_rules(const MODULECMD_ARG *argv) bool dbfw_show_rules(const MODULECMD_ARG *argv)
{ {
DCB *dcb = argv->argv[0].value.dcb; DCB *dcb = argv->argv[0].value.dcb;
FILTER_DEF *filter = argv->argv[1].value.filter; MXS_FILTER_DEF *filter = argv->argv[1].value.filter;
FW_INSTANCE *inst = (FW_INSTANCE*)filter->filter; FW_INSTANCE *inst = (FW_INSTANCE*)filter->filter;
dcb_printf(dcb, "Rule, Type, Times Matched\n"); dcb_printf(dcb, "Rule, Type, Times Matched\n");

View File

@ -41,7 +41,7 @@ bool masking_command_reload(const MODULECMD_ARG* pArgs)
DCB* pDcb = pArgs->argv[0].value.dcb; DCB* pDcb = pArgs->argv[0].value.dcb;
ss_dassert(pDcb); ss_dassert(pDcb);
const FILTER_DEF* pFilterDef = pArgs->argv[1].value.filter; const MXS_FILTER_DEF* pFilterDef = pArgs->argv[1].value.filter;
ss_dassert(pFilterDef); ss_dassert(pFilterDef);
if (strcmp(pFilterDef->module, "masking") == 0) if (strcmp(pFilterDef->module, "masking") == 0)

View File

@ -1,167 +0,0 @@
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <mysql.h>
using namespace std;
namespace
{
void print_usage_and_exit(ostream& out, const char* zName)
{
out << "usage: " << zName << "[-h host] [-P port] [-u user] [-p password] -s statement" << endl;
exit(EXIT_FAILURE);
}
int test_prepared(MYSQL* pMysql, const char* zStatement)
{
int rc = EXIT_FAILURE;
MYSQL_STMT* pStmt = mysql_stmt_init(pMysql);
if (pStmt)
{
if (mysql_stmt_prepare(pStmt, zStatement, strlen(zStatement)) == 0)
{
if (mysql_stmt_execute(pStmt) == 0)
{
int nColumns = mysql_stmt_field_count(pStmt);
cout << "Columns: " << nColumns << endl;
typedef char Buffer[256];
Buffer buffers[nColumns];
MYSQL_BIND bind[nColumns];
unsigned long lengths[nColumns];
my_bool nulls[nColumns];
for (int i = 0; i < nColumns; ++i)
{
memset(&bind[i], 0, sizeof(MYSQL_BIND));
bind[i].buffer_type = MYSQL_TYPE_STRING;
bind[i].buffer = buffers[i];
bind[i].buffer_length = 256;
bind[i].length = &lengths[i];
bind[i].is_null = &nulls[i];
}
if (mysql_stmt_bind_result(pStmt, bind) == 0)
{
while (mysql_stmt_fetch(pStmt) == 0)
{
for (int j = 0; j < nColumns; ++j)
{
if (nulls[j])
{
cout << "NULL";
}
else
{
cout.write(buffers[j], lengths[j]);
}
if (j < nColumns - 1)
{
cout << ", ";
}
}
cout << endl;
}
}
else
{
cerr << "error (mysql_stmt_bind_result): " << mysql_stmt_error(pStmt) << endl;
}
}
else
{
cerr << "error (mysql_stmt_execute): " << mysql_stmt_error(pStmt) << endl;
}
}
else
{
cerr << "error (mysql_stmt_prepare): " << mysql_stmt_error(pStmt) << endl;
}
mysql_stmt_close(pStmt);
}
else
{
cerr << "error (mysql_stmt_init): " << mysql_error(pMysql) << endl;
}
return rc;
}
}
int main(int argc, char* argv[])
{
int rc = EXIT_FAILURE;
const char* zHost = "127.0.0.1";
int port = 3306;
const char* zUser = getenv("USER");
const char* zPassword = NULL;
const char* zStatement = NULL;
int opt;
while ((opt = getopt(argc, argv, "h:P:u:p:s:")) != -1)
{
switch (opt)
{
case 'h':
zHost = optarg;
break;
case 'p':
zPassword = optarg;
break;
case 'u':
zUser = optarg;
break;
case 'P':
port = atoi(optarg);
break;
case 's':
zStatement = optarg;
break;
default:
print_usage_and_exit(cerr, argv[0]);
}
}
if (!zStatement)
{
print_usage_and_exit(cerr, argv[0]);
}
MYSQL* pMysql = mysql_init(NULL);
if (pMysql)
{
if (mysql_real_connect(pMysql, zHost, zUser, zPassword, NULL, port, NULL, 0))
{
rc = test_prepared(pMysql, zStatement);
}
else
{
cerr << "error: " << mysql_error(pMysql) << endl;
}
mysql_close(pMysql);
pMysql = NULL;
}
else
{
cerr << "error: " << mysql_error(NULL) << endl;
}
return rc;
}

View File

@ -1524,7 +1524,7 @@ convert_arg(char *arg, int arg_type)
break; break;
case ARG_TYPE_FILTER: case ARG_TYPE_FILTER:
rval = (unsigned long)filter_find(arg); rval = (unsigned long)filter_def_find(arg);
break; break;
case ARG_TYPE_NUMERIC: case ARG_TYPE_NUMERIC: