From 2611f9a701b2872f76711e6a1b3d078ee507f31c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 5 Jan 2017 16:22:34 +0200 Subject: [PATCH] Give parameters as CONFIG_PARAMETER for FILTER::createInstance The filters should use the same configuration parameters as other modules use. This allows them to use the common configuration management functions to get values from it. --- include/maxscale/filter.h | 14 +--- include/maxscale/filter.hh | 2 +- server/core/filter.c | 43 ++---------- server/modules/filter/cache/cachefilter.cc | 12 ++-- server/modules/filter/cache/cachefilter.hh | 4 +- server/modules/filter/ccrfilter/ccrfilter.c | 26 +++---- server/modules/filter/dbfwfilter/dbfwfilter.c | 32 ++++----- server/modules/filter/hintfilter/hintfilter.c | 4 +- server/modules/filter/luafilter/luafilter.c | 19 +++-- .../modules/filter/masking/maskingfilter.cc | 4 +- .../modules/filter/masking/maskingfilter.hh | 4 +- server/modules/filter/maxrows/maxrows.c | 32 ++++----- server/modules/filter/mqfilter/mqfilter.c | 70 +++++++++---------- .../namedserverfilter/namedserverfilter.c | 27 ++++--- server/modules/filter/qlafilter/qlafilter.c | 31 ++++---- .../modules/filter/regexfilter/regexfilter.c | 35 +++++----- server/modules/filter/tee/tee.c | 33 +++++---- server/modules/filter/testfilter/testfilter.c | 4 +- server/modules/filter/topfilter/topfilter.c | 35 +++++----- server/modules/filter/tpmfilter/tpmfilter.c | 32 ++++----- 20 files changed, 206 insertions(+), 257 deletions(-) diff --git a/include/maxscale/filter.h b/include/maxscale/filter.h index 3b25b4483..86750c537 100644 --- a/include/maxscale/filter.h +++ b/include/maxscale/filter.h @@ -23,6 +23,7 @@ */ #include +#include #include #include #include @@ -37,15 +38,6 @@ MXS_BEGIN_DECLS */ typedef void *FILTER; -/** - * The structure used to pass name, value pairs to the filter instances - */ -typedef struct -{ - char *name; /**< Name of the parameter */ - char *value; /**< Value of the parameter */ -} FILTER_PARAMETER; - /** * @verbatim * The "module object" structure for a query router module @@ -73,7 +65,7 @@ typedef struct filter_object { FILTER *(*createInstance)(const char *name, char **options, - FILTER_PARAMETER **params); + CONFIG_PARAMETER *params); void *(*newSession)(FILTER *instance, SESSION *session); void (*closeSession)(FILTER *instance, void *fsession); void (*freeSession)(FILTER *instance, void *fsession); @@ -102,7 +94,7 @@ typedef struct filter_def char *name; /**< The Filter name */ char *module; /**< The module to load */ char **options; /**< The options set for this filter */ - FILTER_PARAMETER **parameters; /**< The filter parameters */ + CONFIG_PARAMETER *parameters; /**< The filter parameters */ FILTER filter; /**< The runtime filter */ FILTER_OBJECT *obj; /**< The "MODULE_OBJECT" for the filter */ SPINLOCK spin; /**< Spinlock to protect the filter definition */ diff --git a/include/maxscale/filter.hh b/include/maxscale/filter.hh index fe241548b..e0d9ba9e1 100644 --- a/include/maxscale/filter.hh +++ b/include/maxscale/filter.hh @@ -203,7 +203,7 @@ template class Filter { public: - static FILTER* createInstance(const char* zName, char** pzOptions, FILTER_PARAMETER** ppParams) + static FILTER* createInstance(const char* zName, char** pzOptions, CONFIG_PARAMETER* ppParams) { FilterType* pFilter = NULL; diff --git a/server/core/filter.c b/server/core/filter.c index 9536d4c2c..8996ac72e 100644 --- a/server/core/filter.c +++ b/server/core/filter.c @@ -325,36 +325,11 @@ filter_add_option(FILTER_DEF *filter, const char *option) void filter_add_parameter(FILTER_DEF *filter, const char *name, const char *value) { - int i; + CONFIG_CONTEXT ctx = {.object = ""}; - spinlock_acquire(&filter->spin); - FILTER_PARAMETER **parameters; - if (filter->parameters == NULL) - { - parameters = (FILTER_PARAMETER **)MXS_CALLOC(2, sizeof(FILTER_PARAMETER *)); - i = 0; - } - else - { - for (i = 0; filter->parameters[i]; i++) - { - ; - } - parameters = (FILTER_PARAMETER **)MXS_REALLOC(filter->parameters, - (i + 2) * sizeof(FILTER_PARAMETER *)); - } - FILTER_PARAMETER *parameter = MXS_CALLOC(1, sizeof(FILTER_PARAMETER)); - char* my_name = MXS_STRDUP(name); - char* my_value = MXS_STRDUP(value); - - MXS_ABORT_IF_TRUE(!parameters || !parameter || !my_name || !my_value); - - parameter->name = my_name; - parameter->value = my_value; - parameters[i] = parameter; - parameters[i + 1] = NULL; - filter->parameters = parameters; - spinlock_release(&filter->spin); + config_add_param(&ctx, name, value); + ctx.parameters->next = filter->parameters; + filter->parameters = ctx.parameters; } /** @@ -363,15 +338,7 @@ filter_add_parameter(FILTER_DEF *filter, const char *name, const char *value) */ static void filter_free_parameters(FILTER_DEF *filter) { - if (filter->parameters) - { - for (int i = 0; filter->parameters[i]; i++) - { - MXS_FREE(filter->parameters[i]->name); - MXS_FREE(filter->parameters[i]->value); - } - MXS_FREE(filter->parameters); - } + config_parameter_free(filter->parameters); } /** diff --git a/server/modules/filter/cache/cachefilter.cc b/server/modules/filter/cache/cachefilter.cc index 6cc6a1964..8cc1d0a08 100644 --- a/server/modules/filter/cache/cachefilter.cc +++ b/server/modules/filter/cache/cachefilter.cc @@ -136,7 +136,7 @@ bool cache_command_show(const MODULECMD_ARG* pArgs) * * @return True if the parameter was an unsigned integer. */ -bool config_get_uint32(const FILTER_PARAMETER& param, uint32_t* pValue) +bool config_get_uint32(const CONFIG_PARAMETER& param, uint32_t* pValue) { bool rv = false; char* end; @@ -167,7 +167,7 @@ bool config_get_uint32(const FILTER_PARAMETER& param, uint32_t* pValue) * * @return True if the parameter was an unsigned integer. */ -bool config_get_uint64(const FILTER_PARAMETER& param, uint64_t* pValue) +bool config_get_uint64(const CONFIG_PARAMETER& param, uint64_t* pValue) { bool rv = false; char* end; @@ -241,7 +241,7 @@ CacheFilter::~CacheFilter() } // static -CacheFilter* CacheFilter::create(const char* zName, char** pzOptions, FILTER_PARAMETER** ppParams) +CacheFilter* CacheFilter::create(const char* zName, char** pzOptions, CONFIG_PARAMETER* ppParams) { CacheFilter* pFilter = new CacheFilter; @@ -301,14 +301,12 @@ uint64_t CacheFilter::getCapabilities() } // static -bool CacheFilter::process_params(char **pzOptions, FILTER_PARAMETER **ppParams, CACHE_CONFIG& config) +bool CacheFilter::process_params(char **pzOptions, CONFIG_PARAMETER *ppParams, CACHE_CONFIG& config) { bool error = false; - for (int i = 0; ppParams[i]; ++i) + for (const CONFIG_PARAMETER *pParam = ppParams; pParam; pParam = pParam->next) { - const FILTER_PARAMETER *pParam = ppParams[i]; - if (strcmp(pParam->name, "max_resultset_rows") == 0) { if (!config_get_uint64(*pParam, &config.max_resultset_rows)) diff --git a/server/modules/filter/cache/cachefilter.hh b/server/modules/filter/cache/cachefilter.hh index 972e889c6..64ee496fc 100644 --- a/server/modules/filter/cache/cachefilter.hh +++ b/server/modules/filter/cache/cachefilter.hh @@ -22,7 +22,7 @@ class CacheFilter : public maxscale::Filter public: ~CacheFilter(); - static CacheFilter* create(const char* zName, char** pzOptions, FILTER_PARAMETER** ppParams); + static CacheFilter* create(const char* zName, char** pzOptions, CONFIG_PARAMETER* ppParams); Cache& cache() { ss_dassert(m_sCache.get()); return *m_sCache.get(); } const Cache& cache() const { ss_dassert(m_sCache.get()); return *m_sCache.get(); } @@ -39,7 +39,7 @@ private: CacheFilter(const CacheFilter&); CacheFilter& operator = (const CacheFilter&); - static bool process_params(char **pzOptions, FILTER_PARAMETER **ppParams, CACHE_CONFIG& config); + static bool process_params(char **pzOptions, CONFIG_PARAMETER *ppParams, CACHE_CONFIG& config); private: CACHE_CONFIG m_config; diff --git a/server/modules/filter/ccrfilter/ccrfilter.c b/server/modules/filter/ccrfilter/ccrfilter.c index 89eba5d5a..58cd24f07 100644 --- a/server/modules/filter/ccrfilter/ccrfilter.c +++ b/server/modules/filter/ccrfilter/ccrfilter.c @@ -46,7 +46,7 @@ * @endverbatim */ -static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **params); +static FILTER *createInstance(const char *name, char **options, CONFIG_PARAMETER *params); static void *newSession(FILTER *instance, SESSION *session); static void closeSession(FILTER *instance, void *session); static void freeSession(FILTER *instance, void *session); @@ -147,7 +147,7 @@ MXS_MODULE* MXS_CREATE_MODULE() * @return The instance data for this new instance */ static FILTER * -createInstance(const char *name, char **options, FILTER_PARAMETER **params) +createInstance(const char *name, char **options, CONFIG_PARAMETER *params) { CCR_INSTANCE *my_instance; int i; @@ -163,27 +163,27 @@ createInstance(const char *name, char **options, FILTER_PARAMETER **params) my_instance->match = NULL; my_instance->nomatch = NULL; - for (i = 0; params && params[i]; i++) + for (const CONFIG_PARAMETER *p = params; p; p = p->next) { - if (!strcmp(params[i]->name, "count")) + if (!strcmp(p->name, "count")) { - my_instance->count = atoi(params[i]->value); + my_instance->count = atoi(p->value); } - else if (!strcmp(params[i]->name, "time")) + else if (!strcmp(p->name, "time")) { - my_instance->time = atoi(params[i]->value); + my_instance->time = atoi(p->value); } - else if (!strcmp(params[i]->name, "match")) + else if (!strcmp(p->name, "match")) { - my_instance->match = MXS_STRDUP_A(params[i]->value); + my_instance->match = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "ignore")) + else if (!strcmp(p->name, "ignore")) { - my_instance->nomatch = MXS_STRDUP_A(params[i]->value); + my_instance->nomatch = MXS_STRDUP_A(p->value); } - else if (!filter_standard_parameter(params[i]->name)) + else if (!filter_standard_parameter(p->name)) { - MXS_ERROR("ccrfilter: Unexpected parameter '%s'.\n", params[i]->name); + MXS_ERROR("ccrfilter: Unexpected parameter '%s'.\n", p->name); } } diff --git a/server/modules/filter/dbfwfilter/dbfwfilter.c b/server/modules/filter/dbfwfilter/dbfwfilter.c index 0fd3e7da2..061eacc5b 100644 --- a/server/modules/filter/dbfwfilter/dbfwfilter.c +++ b/server/modules/filter/dbfwfilter/dbfwfilter.c @@ -94,7 +94,7 @@ int dbfw_yyparse(void*); /* * The filter entry points */ -static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **); +static FILTER *createInstance(const char *name, char **options, CONFIG_PARAMETER *); static void *newSession(FILTER *instance, SESSION *session); static void closeSession(FILTER *instance, void *session); static void freeSession(FILTER *instance, void *session); @@ -1484,7 +1484,7 @@ bool replace_rules(FW_INSTANCE* instance) * @return The instance data for this new instance */ static FILTER * -createInstance(const char *name, char **options, FILTER_PARAMETER **params) +createInstance(const char *name, char **options, CONFIG_PARAMETER *params) { FW_INSTANCE *my_instance; int i; @@ -1501,46 +1501,46 @@ createInstance(const char *name, char **options, FILTER_PARAMETER **params) my_instance->action = FW_ACTION_BLOCK; my_instance->log_match = FW_LOG_NONE; - for (i = 0; params[i]; i++) + for (const CONFIG_PARAMETER *p = params; p; p = p->next) { - if (strcmp(params[i]->name, "rules") == 0) + if (strcmp(p->name, "rules") == 0) { - filename = params[i]->value; + filename = p->value; } - else if (strcmp(params[i]->name, "log_match") == 0 && - config_truth_value(params[i]->value)) + else if (strcmp(p->name, "log_match") == 0 && + config_truth_value(p->value)) { my_instance->log_match |= FW_LOG_MATCH; } - else if (strcmp(params[i]->name, "log_no_match") == 0 && - config_truth_value(params[i]->value)) + else if (strcmp(p->name, "log_no_match") == 0 && + config_truth_value(p->value)) { my_instance->log_match |= FW_LOG_NO_MATCH; } - else if (strcmp(params[i]->name, "action") == 0) + else if (strcmp(p->name, "action") == 0) { - if (strcmp(params[i]->value, "allow") == 0) + if (strcmp(p->value, "allow") == 0) { my_instance->action = FW_ACTION_ALLOW; } - else if (strcmp(params[i]->value, "block") == 0) + else if (strcmp(p->value, "block") == 0) { my_instance->action = FW_ACTION_BLOCK; } - else if (strcmp(params[i]->value, "ignore") == 0) + else if (strcmp(p->value, "ignore") == 0) { my_instance->action = FW_ACTION_IGNORE; } else { MXS_ERROR("Unknown value for %s: %s. Expected one of 'allow', " - "'block' or 'ignore'.", params[i]->name, params[i]->value); + "'block' or 'ignore'.", p->name, p->value); err = true; } } - else if (!filter_standard_parameter(params[i]->name)) + else if (!filter_standard_parameter(p->name)) { - MXS_ERROR("Unknown parameter '%s' for dbfwfilter.", params[i]->name); + MXS_ERROR("Unknown parameter '%s' for dbfwfilter.", p->name); err = true; } } diff --git a/server/modules/filter/hintfilter/hintfilter.c b/server/modules/filter/hintfilter/hintfilter.c index 493014283..83f1fd3f6 100644 --- a/server/modules/filter/hintfilter/hintfilter.c +++ b/server/modules/filter/hintfilter/hintfilter.c @@ -23,7 +23,7 @@ * */ -static FILTER *createInstance(const char* name, char **options, FILTER_PARAMETER **params); +static FILTER *createInstance(const char* name, char **options, CONFIG_PARAMETER *params); static void *newSession(FILTER *instance, SESSION *session); static void closeSession(FILTER *instance, void *session); static void freeSession(FILTER *instance, void *session); @@ -88,7 +88,7 @@ MXS_MODULE* MXS_CREATE_MODULE() * @return The instance data for this new instance */ static FILTER * -createInstance(const char *name, char **options, FILTER_PARAMETER **params) +createInstance(const char *name, char **options, CONFIG_PARAMETER *params) { HINT_INSTANCE *my_instance; diff --git a/server/modules/filter/luafilter/luafilter.c b/server/modules/filter/luafilter/luafilter.c index 0d2718ee1..70c736485 100644 --- a/server/modules/filter/luafilter/luafilter.c +++ b/server/modules/filter/luafilter/luafilter.c @@ -53,7 +53,7 @@ /* * The filter entry points */ -static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **); +static FILTER *createInstance(const char *name, char **options, CONFIG_PARAMETER *); static void *newSession(FILTER *instance, SESSION *session); static void closeSession(FILTER *instance, void *session); static void freeSession(FILTER *instance, void *session); @@ -97,7 +97,6 @@ MXS_MODULE* MXS_CREATE_MODULE() "Lua Filter", "V1.0.0", &MyObject, - NULL, /* Parameters */ NULL, /* Process init. */ NULL, /* Process finish. */ NULL, /* Thread init. */ @@ -197,7 +196,7 @@ typedef struct * @return The instance data for this new instance */ static FILTER * -createInstance(const char *name, char **options, FILTER_PARAMETER **params) +createInstance(const char *name, char **options, CONFIG_PARAMETER *params) { LUA_INSTANCE *my_instance; bool error = false; @@ -209,19 +208,19 @@ createInstance(const char *name, char **options, FILTER_PARAMETER **params) spinlock_init(&my_instance->lock); - for (int i = 0; params[i] && !error; i++) + for (CONFIG_PARAMETER *p = p; p && !error; p = p->next) { - if (strcmp(params[i]->name, "global_script") == 0) + if (strcmp(p->name, "global_script") == 0) { - error = (my_instance->global_script = MXS_STRDUP(params[i]->value)) == NULL; + error = (my_instance->global_script = MXS_STRDUP(p->value)) == NULL; } - else if (strcmp(params[i]->name, "session_script") == 0) + else if (strcmp(p->name, "session_script") == 0) { - error = (my_instance->session_script = MXS_STRDUP(params[i]->value)) == NULL; + error = (my_instance->session_script = MXS_STRDUP(p->value)) == NULL; } - else if (!filter_standard_parameter(params[i]->name)) + else if (!filter_standard_parameter(p->name)) { - MXS_ERROR("Unexpected parameter '%s'", params[i]->name); + MXS_ERROR("Unexpected parameter '%s'", p->name); error = true; } } diff --git a/server/modules/filter/masking/maskingfilter.cc b/server/modules/filter/masking/maskingfilter.cc index 97d7ea9c3..ae949578a 100644 --- a/server/modules/filter/masking/maskingfilter.cc +++ b/server/modules/filter/masking/maskingfilter.cc @@ -55,7 +55,7 @@ MaskingFilter::~MaskingFilter() } // static -MaskingFilter* MaskingFilter::create(const char* zName, char** pzOptions, FILTER_PARAMETER** ppParams) +MaskingFilter* MaskingFilter::create(const char* zName, char** pzOptions, CONFIG_PARAMETER* ppParams) { MaskingFilter* pFilter = new MaskingFilter; @@ -87,7 +87,7 @@ uint64_t MaskingFilter::getCapabilities() } // static -bool MaskingFilter::process_params(char **pzOptions, FILTER_PARAMETER **ppParams, Config& config) +bool MaskingFilter::process_params(char **pzOptions, CONFIG_PARAMETER *ppParams, Config& config) { return true; } diff --git a/server/modules/filter/masking/maskingfilter.hh b/server/modules/filter/masking/maskingfilter.hh index d23ce544f..fe774f496 100644 --- a/server/modules/filter/masking/maskingfilter.hh +++ b/server/modules/filter/masking/maskingfilter.hh @@ -24,7 +24,7 @@ public: typedef MaskingFilterConfig Config; ~MaskingFilter(); - static MaskingFilter* create(const char* zName, char** pzOptions, FILTER_PARAMETER** ppParams); + static MaskingFilter* create(const char* zName, char** pzOptions, CONFIG_PARAMETER* ppParams); MaskingFilterSession* newSession(SESSION* pSession); @@ -38,7 +38,7 @@ private: MaskingFilter(const MaskingFilter&); MaskingFilter& operator = (const MaskingFilter&); - static bool process_params(char **pzOptions, FILTER_PARAMETER **ppParams, Config& config); + static bool process_params(char **pzOptions, CONFIG_PARAMETER *ppParams, Config& config); private: Config m_config; diff --git a/server/modules/filter/maxrows/maxrows.c b/server/modules/filter/maxrows/maxrows.c index d7aae3bee..22f9b5713 100644 --- a/server/modules/filter/maxrows/maxrows.c +++ b/server/modules/filter/maxrows/maxrows.c @@ -46,7 +46,7 @@ #include #include "maxrows.h" -static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **); +static FILTER *createInstance(const char *name, char **options, CONFIG_PARAMETER *); static void *newSession(FILTER *instance, SESSION *session); static void closeSession(FILTER *instance, void *sdata); static void freeSession(FILTER *instance, void *sdata); @@ -163,7 +163,7 @@ static int handle_expecting_nothing(MAXROWS_SESSION_DATA *csdata); static int handle_expecting_response(MAXROWS_SESSION_DATA *csdata); static int handle_rows(MAXROWS_SESSION_DATA *csdata); static int handle_ignoring_response(MAXROWS_SESSION_DATA *csdata); -static bool process_params(char **options, FILTER_PARAMETER **params, MAXROWS_CONFIG* config); +static bool process_params(char **options, CONFIG_PARAMETER *params, MAXROWS_CONFIG* config); static int send_upstream(MAXROWS_SESSION_DATA *csdata); static int send_ok_upstream(MAXROWS_SESSION_DATA *csdata); @@ -180,7 +180,7 @@ static int send_ok_upstream(MAXROWS_SESSION_DATA *csdata); * * @return The instance data for this new instance */ -static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **params) +static FILTER *createInstance(const char *name, char **options, CONFIG_PARAMETER *params) { MAXROWS_INSTANCE *cinstance = NULL; MAXROWS_CONFIG config = DEFAULT_CONFIG; @@ -882,22 +882,20 @@ static int handle_ignoring_response(MAXROWS_SESSION_DATA *csdata) * * @return True if all parameters could be processed, false otherwise. */ -static bool process_params(char **options, FILTER_PARAMETER **params, MAXROWS_CONFIG* config) +static bool process_params(char **options, CONFIG_PARAMETER *params, MAXROWS_CONFIG* config) { bool error = false; - for (int i = 0; params[i]; ++i) + for (const CONFIG_PARAMETER *p = params; p; p = p->next) { - const FILTER_PARAMETER *param = params[i]; - /* We could add a new parameter, max_resultset_columns: * This way if result has more than max_resultset_columns * we return 0 result */ - if (strcmp(param->name, "max_resultset_rows") == 0) + if (strcmp(p->name, "max_resultset_rows") == 0) { - int v = atoi(param->value); + int v = atoi(p->value); if (v > 0) { @@ -908,9 +906,9 @@ static bool process_params(char **options, FILTER_PARAMETER **params, MAXROWS_CO config->max_resultset_rows = MAXROWS_DEFAULT_MAX_RESULTSET_ROWS; } } - else if (strcmp(param->name, "max_resultset_size") == 0) + else if (strcmp(p->name, "max_resultset_size") == 0) { - int v = atoi(param->value); + int v = atoi(p->value); if (v > 0) { @@ -919,13 +917,13 @@ static bool process_params(char **options, FILTER_PARAMETER **params, MAXROWS_CO else { MXS_ERROR("The value of the configuration entry '%s' must " - "be an integer larger than 0.", param->name); + "be an integer larger than 0.", p->name); error = true; } } - else if (strcmp(param->name, "debug") == 0) + else if (strcmp(p->name, "debug") == 0) { - int v = atoi(param->value); + int v = atoi(p->value); if ((v >= MAXROWS_DEBUG_MIN) && (v <= MAXROWS_DEBUG_MAX)) { @@ -935,13 +933,13 @@ static bool process_params(char **options, FILTER_PARAMETER **params, MAXROWS_CO { MXS_ERROR("The value of the configuration entry '%s' must " "be between %d and %d, inclusive.", - param->name, MAXROWS_DEBUG_MIN, MAXROWS_DEBUG_MAX); + p->name, MAXROWS_DEBUG_MIN, MAXROWS_DEBUG_MAX); error = true; } } - else if (!filter_standard_parameter(params[i]->name)) + else if (!filter_standard_parameter(p->name)) { - MXS_ERROR("Unknown configuration entry '%s'.", param->name); + MXS_ERROR("Unknown configuration entry '%s'.", p->name); error = true; } } diff --git a/server/modules/filter/mqfilter/mqfilter.c b/server/modules/filter/mqfilter/mqfilter.c index b0a2d60dd..c273c37ac 100644 --- a/server/modules/filter/mqfilter/mqfilter.c +++ b/server/modules/filter/mqfilter/mqfilter.c @@ -83,7 +83,7 @@ static int hktask_id = 0; /* * The filter entry points */ -static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **); +static FILTER *createInstance(const char *name, char **options, CONFIG_PARAMETER *); static void *newSession(FILTER *instance, SESSION *session); static void closeSession(FILTER *instance, void *session); static void freeSession(FILTER *instance, void *session); @@ -490,11 +490,11 @@ char** parse_optstr(char* str, char* tok, int* szstore) * @return The instance data for this new instance */ static FILTER * -createInstance(const char *name, char **options, FILTER_PARAMETER **params) +createInstance(const char *name, char **options, CONFIG_PARAMETER *params) { MQ_INSTANCE *my_instance; int paramcount = 0, parammax = 64, i = 0, x = 0, arrsize = 0; - FILTER_PARAMETER** paramlist; + CONFIG_PARAMETER** paramlist; char** arr = NULL; char taskname[512]; @@ -503,7 +503,7 @@ createInstance(const char *name, char **options, FILTER_PARAMETER **params) spinlock_init(&my_instance->rconn_lock); spinlock_init(&my_instance->msg_lock); uid_gen = 0; - paramlist = MXS_MALLOC(sizeof(FILTER_PARAMETER*) * 64); + paramlist = MXS_MALLOC(sizeof(CONFIG_PARAMETER*) * 64); MXS_ABORT_IF_NULL(paramlist); if ((my_instance->conn = amqp_new_connection()) == NULL) @@ -521,63 +521,63 @@ createInstance(const char *name, char **options, FILTER_PARAMETER **params) my_instance->log_all = false; my_instance->strict_logging = true; - for (i = 0; params[i]; i++) + for (const CONFIG_PARAMETER *p = p; p; p = p->next) { - if (!strcmp(params[i]->name, "hostname")) + if (!strcmp(p->name, "hostname")) { - my_instance->hostname = MXS_STRDUP_A(params[i]->value); + my_instance->hostname = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "username")) + else if (!strcmp(p->name, "username")) { - my_instance->username = MXS_STRDUP_A(params[i]->value); + my_instance->username = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "password")) + else if (!strcmp(p->name, "password")) { - my_instance->password = MXS_STRDUP_A(params[i]->value); + my_instance->password = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "vhost")) + else if (!strcmp(p->name, "vhost")) { - my_instance->vhost = MXS_STRDUP_A(params[i]->value); + my_instance->vhost = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "port")) + else if (!strcmp(p->name, "port")) { - my_instance->port = atoi(params[i]->value); + my_instance->port = atoi(p->value); } - else if (!strcmp(params[i]->name, "exchange")) + else if (!strcmp(p->name, "exchange")) { - my_instance->exchange = MXS_STRDUP_A(params[i]->value); + my_instance->exchange = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "key")) + else if (!strcmp(p->name, "key")) { - my_instance->key = MXS_STRDUP_A(params[i]->value); + my_instance->key = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "queue")) + else if (!strcmp(p->name, "queue")) { - my_instance->queue = MXS_STRDUP_A(params[i]->value); + my_instance->queue = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "ssl_client_certificate")) + else if (!strcmp(p->name, "ssl_client_certificate")) { - my_instance->ssl_client_cert = MXS_STRDUP_A(params[i]->value); + my_instance->ssl_client_cert = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "ssl_client_key")) + else if (!strcmp(p->name, "ssl_client_key")) { - my_instance->ssl_client_key = MXS_STRDUP_A(params[i]->value); + my_instance->ssl_client_key = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "ssl_CA_cert")) + else if (!strcmp(p->name, "ssl_CA_cert")) { - my_instance->ssl_CA_cert = MXS_STRDUP_A(params[i]->value); + my_instance->ssl_CA_cert = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "exchange_type")) + else if (!strcmp(p->name, "exchange_type")) { - my_instance->exchange_type = MXS_STRDUP_A(params[i]->value); + my_instance->exchange_type = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "logging_trigger")) + else if (!strcmp(p->name, "logging_trigger")) { - arr = parse_optstr(params[i]->value, ",", &arrsize); + arr = parse_optstr(p->value, ",", &arrsize); for (x = 0; x < arrsize; x++) { @@ -617,15 +617,15 @@ createInstance(const char *name, char **options, FILTER_PARAMETER **params) } - else if (strstr(params[i]->name, "logging_")) + else if (strstr(p->name, "logging_")) { if (paramcount < parammax) { - paramlist[paramcount] = MXS_MALLOC(sizeof(FILTER_PARAMETER)); + paramlist[paramcount] = MXS_MALLOC(sizeof(CONFIG_PARAMETER)); MXS_ABORT_IF_NULL(paramlist[paramcount]); - paramlist[paramcount]->name = MXS_STRDUP_A(params[i]->name); - paramlist[paramcount]->value = MXS_STRDUP_A(params[i]->value); + paramlist[paramcount]->name = MXS_STRDUP_A(p->name); + paramlist[paramcount]->value = MXS_STRDUP_A(p->value); paramcount++; } } diff --git a/server/modules/filter/namedserverfilter/namedserverfilter.c b/server/modules/filter/namedserverfilter/namedserverfilter.c index 2e50220b9..d4ed20670 100644 --- a/server/modules/filter/namedserverfilter/namedserverfilter.c +++ b/server/modules/filter/namedserverfilter/namedserverfilter.c @@ -40,7 +40,7 @@ * @endverbatim */ -static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **params); +static FILTER *createInstance(const char *name, char **options, CONFIG_PARAMETER *params); static void *newSession(FILTER *instance, SESSION *session); static void closeSession(FILTER *instance, void *session); static void freeSession(FILTER *instance, void *session); @@ -128,7 +128,7 @@ MXS_MODULE* MXS_CREATE_MODULE() * @return The instance data for this new instance */ static FILTER * -createInstance(const char *name, char **options, FILTER_PARAMETER **params) +createInstance(const char *name, char **options, CONFIG_PARAMETER *params) { REGEXHINT_INSTANCE *my_instance = (REGEXHINT_INSTANCE*)MXS_MALLOC(sizeof(REGEXHINT_INSTANCE)); @@ -140,28 +140,27 @@ createInstance(const char *name, char **options, FILTER_PARAMETER **params) my_instance->user = NULL; bool error = false; - for (int i = 0; params && params[i]; i++) + for (const CONFIG_PARAMETER *p = params; p; p = p->next) { - if (!strcmp(params[i]->name, "match")) + if (!strcmp(p->name, "match")) { - my_instance->match = MXS_STRDUP_A(params[i]->value); + my_instance->match = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "server")) + else if (!strcmp(p->name, "server")) { - my_instance->server = MXS_STRDUP_A(params[i]->value); + my_instance->server = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "source")) + else if (!strcmp(p->name, "source")) { - my_instance->source = MXS_STRDUP_A(params[i]->value); + my_instance->source = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "user")) + else if (!strcmp(p->name, "user")) { - my_instance->user = MXS_STRDUP_A(params[i]->value); + my_instance->user = MXS_STRDUP_A(p->value); } - else if (!filter_standard_parameter(params[i]->name)) + else if (!filter_standard_parameter(p->name)) { - MXS_ERROR("namedserverfilter: Unexpected parameter '%s'.", - params[i]->name); + MXS_ERROR("namedserverfilter: Unexpected parameter '%s'.", p->name); error = true; } } diff --git a/server/modules/filter/qlafilter/qlafilter.c b/server/modules/filter/qlafilter/qlafilter.c index 51d9094e5..7708a2974 100644 --- a/server/modules/filter/qlafilter/qlafilter.c +++ b/server/modules/filter/qlafilter/qlafilter.c @@ -70,7 +70,7 @@ /* * The filter entry points */ -static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **); +static FILTER *createInstance(const char *name, char **options, CONFIG_PARAMETER *); static void *newSession(FILTER *instance, SESSION *session); static void closeSession(FILTER *instance, void *session); static void freeSession(FILTER *instance, void *session); @@ -187,7 +187,7 @@ MXS_MODULE* MXS_CREATE_MODULE() * @return The instance data for this new instance */ static FILTER * -createInstance(const char *name, char **options, FILTER_PARAMETER **params) +createInstance(const char *name, char **options, CONFIG_PARAMETER *params) { QLA_INSTANCE *my_instance = (QLA_INSTANCE*) MXS_MALLOC(sizeof(QLA_INSTANCE)); @@ -209,32 +209,31 @@ createInstance(const char *name, char **options, FILTER_PARAMETER **params) if (params) { - for (int i = 0; params[i]; i++) + for (const CONFIG_PARAMETER *p = params; p; p = p->next) { - if (!strcmp(params[i]->name, "match")) + if (!strcmp(p->name, "match")) { - my_instance->match = MXS_STRDUP_A(params[i]->value); + my_instance->match = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "exclude")) + else if (!strcmp(p->name, "exclude")) { - my_instance->nomatch = MXS_STRDUP_A(params[i]->value); + my_instance->nomatch = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "source")) + else if (!strcmp(p->name, "source")) { - my_instance->source = MXS_STRDUP_A(params[i]->value); + my_instance->source = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "user")) + else if (!strcmp(p->name, "user")) { - my_instance->user_name = MXS_STRDUP_A(params[i]->value); + my_instance->user_name = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "filebase")) + else if (!strcmp(p->name, "filebase")) { - my_instance->filebase = MXS_STRDUP_A(params[i]->value); + my_instance->filebase = MXS_STRDUP_A(p->value); } - else if (!filter_standard_parameter(params[i]->name)) + else if (!filter_standard_parameter(p->name)) { - MXS_ERROR("qlafilter: Unexpected parameter '%s'.", - params[i]->name); + MXS_ERROR("qlafilter: Unexpected parameter '%s'.", p->name); error = true; } } diff --git a/server/modules/filter/regexfilter/regexfilter.c b/server/modules/filter/regexfilter/regexfilter.c index 086e9c450..c90bacd6d 100644 --- a/server/modules/filter/regexfilter/regexfilter.c +++ b/server/modules/filter/regexfilter/regexfilter.c @@ -40,7 +40,7 @@ * @endverbatim */ -static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **params); +static FILTER *createInstance(const char *name, char **options, CONFIG_PARAMETER *params); static void *newSession(FILTER *instance, SESSION *session); static void closeSession(FILTER *instance, void *session); static void freeSession(FILTER *instance, void *session); @@ -164,7 +164,7 @@ void free_instance(REGEX_INSTANCE *instance) * @return The instance data for this new instance */ static FILTER * -createInstance(const char *name, char **options, FILTER_PARAMETER **params) +createInstance(const char *name, char **options, CONFIG_PARAMETER *params) { REGEX_INSTANCE *my_instance; int i, errnumber, cflags = PCRE2_CASELESS; @@ -177,40 +177,39 @@ createInstance(const char *name, char **options, FILTER_PARAMETER **params) my_instance->match = NULL; my_instance->replace = NULL; - for (i = 0; params && params[i]; i++) + for (const CONFIG_PARAMETER *p = params; p; p = p->next) { - if (!strcmp(params[i]->name, "match")) + if (!strcmp(p->name, "match")) { - my_instance->match = MXS_STRDUP_A(params[i]->value); + my_instance->match = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "replace")) + else if (!strcmp(p->name, "replace")) { - my_instance->replace = MXS_STRDUP_A(params[i]->value); + my_instance->replace = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "source")) + else if (!strcmp(p->name, "source")) { - my_instance->source = MXS_STRDUP_A(params[i]->value); + my_instance->source = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "user")) + else if (!strcmp(p->name, "user")) { - my_instance->user = MXS_STRDUP_A(params[i]->value); + my_instance->user = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "log_trace")) + else if (!strcmp(p->name, "log_trace")) { - my_instance->log_trace = config_truth_value(params[i]->value); + my_instance->log_trace = config_truth_value(p->value); } - else if (!strcmp(params[i]->name, "log_file")) + else if (!strcmp(p->name, "log_file")) { if (logfile) { MXS_FREE(logfile); } - logfile = MXS_STRDUP_A(params[i]->value); + logfile = MXS_STRDUP_A(p->value); } - else if (!filter_standard_parameter(params[i]->name)) + else if (!filter_standard_parameter(p->name)) { - MXS_ERROR("regexfilter: Unexpected parameter '%s'.", - params[i]->name); + MXS_ERROR("regexfilter: Unexpected parameter '%s'.", p->name); } } diff --git a/server/modules/filter/tee/tee.c b/server/modules/filter/tee/tee.c index 3bf76fb76..97beb9649 100644 --- a/server/modules/filter/tee/tee.c +++ b/server/modules/filter/tee/tee.c @@ -97,7 +97,7 @@ static unsigned char required_packets[] = /* * The filter entry points */ -static FILTER *createInstance(const char* name, char **options, FILTER_PARAMETER **); +static FILTER *createInstance(const char* name, char **options, CONFIG_PARAMETER *); static void *newSession(FILTER *instance, SESSION *session); static void closeSession(FILTER *instance, void *session); static void freeSession(FILTER *instance, void *session); @@ -342,7 +342,7 @@ MXS_MODULE* MXS_CREATE_MODULE() * @return The instance data for this new instance */ static FILTER * -createInstance(const char *name, char **options, FILTER_PARAMETER **params) +createInstance(const char *name, char **options, CONFIG_PARAMETER *params) { TEE_INSTANCE *my_instance; int i; @@ -361,36 +361,35 @@ createInstance(const char *name, char **options, FILTER_PARAMETER **params) my_instance->nomatch = NULL; if (params) { - for (i = 0; params[i]; i++) + for (const CONFIG_PARAMETER *p = params; p; p = p->next) { - if (!strcmp(params[i]->name, "service")) + if (!strcmp(p->name, "service")) { - if ((my_instance->service = service_find(params[i]->value)) == NULL) + if ((my_instance->service = service_find(p->value)) == NULL) { MXS_ERROR("tee: service '%s' not found.\n", - params[i]->value); + p->value); } } - else if (!strcmp(params[i]->name, "match")) + else if (!strcmp(p->name, "match")) { - my_instance->match = MXS_STRDUP_A(params[i]->value); + my_instance->match = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "exclude")) + else if (!strcmp(p->name, "exclude")) { - my_instance->nomatch = MXS_STRDUP_A(params[i]->value); + my_instance->nomatch = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "source")) + else if (!strcmp(p->name, "source")) { - my_instance->source = MXS_STRDUP_A(params[i]->value); + my_instance->source = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "user")) + else if (!strcmp(p->name, "user")) { - my_instance->userName = MXS_STRDUP_A(params[i]->value); + my_instance->userName = MXS_STRDUP_A(p->value); } - else if (!filter_standard_parameter(params[i]->name)) + else if (!filter_standard_parameter(p->name)) { - MXS_ERROR("tee: Unexpected parameter '%s'.", - params[i]->name); + MXS_ERROR("tee: Unexpected parameter '%s'.", p->name); } } } diff --git a/server/modules/filter/testfilter/testfilter.c b/server/modules/filter/testfilter/testfilter.c index 3312eabeb..8a7f48274 100644 --- a/server/modules/filter/testfilter/testfilter.c +++ b/server/modules/filter/testfilter/testfilter.c @@ -30,7 +30,7 @@ */ -static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **params); +static FILTER *createInstance(const char *name, char **options, CONFIG_PARAMETER *params); static void *newSession(FILTER *instance, SESSION *session); static void closeSession(FILTER *instance, void *session); static void freeSession(FILTER *instance, void *session); @@ -117,7 +117,7 @@ MXS_MODULE* MXS_CREATE_MODULE() * @return The instance data for this new instance */ static FILTER * -createInstance(const char *name, char **options, FILTER_PARAMETER **params) +createInstance(const char *name, char **options, CONFIG_PARAMETER *params) { TEST_INSTANCE *my_instance; diff --git a/server/modules/filter/topfilter/topfilter.c b/server/modules/filter/topfilter/topfilter.c index bb16e8881..6538edeef 100644 --- a/server/modules/filter/topfilter/topfilter.c +++ b/server/modules/filter/topfilter/topfilter.c @@ -48,7 +48,7 @@ /* * The filter entry points */ -static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **); +static FILTER *createInstance(const char *name, char **options, CONFIG_PARAMETER *); static void *newSession(FILTER *instance, SESSION *session); static void closeSession(FILTER *instance, void *session); static void freeSession(FILTER *instance, void *session); @@ -170,7 +170,7 @@ MXS_MODULE* MXS_CREATE_MODULE() * @return The instance data for this new instance */ static FILTER * -createInstance(const char *name, char **options, FILTER_PARAMETER **params) +createInstance(const char *name, char **options, CONFIG_PARAMETER *params) { TOPN_INSTANCE *my_instance = (TOPN_INSTANCE*)MXS_MALLOC(sizeof(TOPN_INSTANCE)); @@ -184,36 +184,35 @@ createInstance(const char *name, char **options, FILTER_PARAMETER **params) my_instance->filebase = NULL; bool error = false; - for (int i = 0; params && params[i]; i++) + for (const CONFIG_PARAMETER *p = params; p; p = p->next) { - if (!strcmp(params[i]->name, "count")) + if (!strcmp(p->name, "count")) { - my_instance->topN = atoi(params[i]->value); + my_instance->topN = atoi(p->value); } - else if (!strcmp(params[i]->name, "filebase")) + else if (!strcmp(p->name, "filebase")) { - my_instance->filebase = MXS_STRDUP_A(params[i]->value); + my_instance->filebase = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "match")) + else if (!strcmp(p->name, "match")) { - my_instance->match = MXS_STRDUP_A(params[i]->value); + my_instance->match = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "exclude")) + else if (!strcmp(p->name, "exclude")) { - my_instance->exclude = MXS_STRDUP_A(params[i]->value); + my_instance->exclude = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "source")) + else if (!strcmp(p->name, "source")) { - my_instance->source = MXS_STRDUP_A(params[i]->value); + my_instance->source = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "user")) + else if (!strcmp(p->name, "user")) { - my_instance->user = MXS_STRDUP_A(params[i]->value); + my_instance->user = MXS_STRDUP_A(p->value); } - else if (!filter_standard_parameter(params[i]->name)) + else if (!filter_standard_parameter(p->name)) { - MXS_ERROR("topfilter: Unexpected parameter '%s'.", - params[i]->name); + MXS_ERROR("topfilter: Unexpected parameter '%s'.", p->name); error = true; } } diff --git a/server/modules/filter/tpmfilter/tpmfilter.c b/server/modules/filter/tpmfilter/tpmfilter.c index 3afc44369..ce80c3caa 100644 --- a/server/modules/filter/tpmfilter/tpmfilter.c +++ b/server/modules/filter/tpmfilter/tpmfilter.c @@ -76,7 +76,7 @@ static const char* default_named_pipe = "/tmp/tpmfilter"; /* * The filter entry points */ -static FILTER *createInstance(const char *name, char **options, FILTER_PARAMETER **); +static FILTER *createInstance(const char *name, char **options, CONFIG_PARAMETER *); static void *newSession(FILTER *instance, SESSION *session); static void closeSession(FILTER *instance, void *session); static void freeSession(FILTER *instance, void *session); @@ -189,7 +189,7 @@ MXS_MODULE* MXS_CREATE_MODULE() * @return The instance data for this new instance */ static FILTER * -createInstance(const char *name, char **options, FILTER_PARAMETER **params) +createInstance(const char *name, char **options, CONFIG_PARAMETER *params) { int i, ret; TPM_INSTANCE *my_instance; @@ -210,35 +210,35 @@ createInstance(const char *name, char **options, FILTER_PARAMETER **params) /* set default named pipe */ my_instance->named_pipe = MXS_STRDUP_A(default_named_pipe); - for (i = 0; params && params[i]; i++) + for (const CONFIG_PARAMETER *p = params; p; p = p->next) { - if (!strcmp(params[i]->name, "filename")) + if (!strcmp(p->name, "filename")) { MXS_FREE(my_instance->filename); - my_instance->filename = MXS_STRDUP_A(params[i]->value); + my_instance->filename = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "source")) + else if (!strcmp(p->name, "source")) { - my_instance->source = MXS_STRDUP_A(params[i]->value); + my_instance->source = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "user")) + else if (!strcmp(p->name, "user")) { - my_instance->user = MXS_STRDUP_A(params[i]->value); + my_instance->user = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "delimiter")) + else if (!strcmp(p->name, "delimiter")) { MXS_FREE(my_instance->delimiter); - my_instance->delimiter = MXS_STRDUP_A(params[i]->value); + my_instance->delimiter = MXS_STRDUP_A(p->value); } - else if (!strcmp(params[i]->name, "query_delimiter")) + else if (!strcmp(p->name, "query_delimiter")) { MXS_FREE(my_instance->query_delimiter); - my_instance->query_delimiter = MXS_STRDUP_A(params[i]->value); + my_instance->query_delimiter = MXS_STRDUP_A(p->value); my_instance->query_delimiter_size = strlen(my_instance->query_delimiter); } - else if (!strcmp(params[i]->name, "named_pipe")) + else if (!strcmp(p->name, "named_pipe")) { - if (params[i]->value == NULL) + if (p->value == NULL) { MXS_ERROR("You need to specify 'named_pipe' for tpmfilter."); MXS_FREE(my_instance); @@ -246,7 +246,7 @@ createInstance(const char *name, char **options, FILTER_PARAMETER **params) } else { - my_instance->named_pipe = MXS_STRDUP_A(params[i]->value); + my_instance->named_pipe = MXS_STRDUP_A(p->value); // check if the file exists first. if (access(my_instance->named_pipe, F_OK) == 0) {