diff --git a/include/maxscale/config.h b/include/maxscale/config.h index 8f9447d5e..798b1dae9 100644 --- a/include/maxscale/config.h +++ b/include/maxscale/config.h @@ -113,21 +113,12 @@ typedef struct char* qc_args; /**< Arguments for the query classifier */ } GATEWAY_CONF; - /** - * @brief Creates an empty configuration context + * @brief Get global MaxScale configuration * - * @param section Context name - * @return New context or NULL on memory allocation failure + * @return The global configuration */ -CONFIG_CONTEXT* config_context_create(const char *section); - -/** - * @brief Free a configuration context - * - * @param context The context to free - */ -void config_context_free(CONFIG_CONTEXT *context); +GATEWAY_CONF* config_get_global_options(); /** * @brief Get a configuration parameter @@ -138,39 +129,6 @@ void config_context_free(CONFIG_CONTEXT *context); */ CONFIG_PARAMETER* config_get_param(CONFIG_PARAMETER* params, const char* name); -/** - * @brief Add a parameter to a configuration context - * - * @param obj Context where the parameter should be added - * @param key Key to add - * @param value Value for the key - * @return True on success, false on memory allocation error - */ -bool config_add_param(CONFIG_CONTEXT* obj, const char* key, const char* value); - -/** - * @brief Append to an existing parameter - * - * @param obj Configuration context - * @param key Parameter name - * @param value Value to append to the parameter - * @return True on success, false on memory allocation error - */ -bool config_append_param(CONFIG_CONTEXT* obj, const char* key, const char* value); - -/** - * @brief Check if all SSL parameters are defined - * - * Helper function to check whether all of the required SSL parameters are defined - * in the configuration context. The checked parameters are 'ssl', 'ssl_key', - * 'ssl_cert' and 'ssl_ca_cert'. The 'ssl' parameter must also have a value of - * 'required'. - * - * @param obj Configuration context - * @return True if all required parameters are present - */ -bool config_have_required_ssl_params(CONFIG_CONTEXT *obj); - /** * @brief Helper function for checking SSL parameters * @@ -179,20 +137,6 @@ bool config_have_required_ssl_params(CONFIG_CONTEXT *obj); */ bool config_is_ssl_parameter(const char *key); -/** - * @brief Construct an SSL structure - * - * The SSL structure is used by both listeners and servers. - * - * TODO: Rename to something like @c config_construct_ssl - * - * @param obj Configuration context - * @param require_cert Whether certificates are required - * @param error_count Pointer to an int which is incremented for each error - * @return New SSL_LISTENER structure or NULL on error - */ -SSL_LISTENER *make_ssl_structure(CONFIG_CONTEXT *obj, bool require_cert, int *error_count); - /** * @brief Check if a configuration parameter is valid * @@ -326,33 +270,46 @@ char* config_copy_string(const CONFIG_PARAMETER *params, const char *key); */ int config_truth_value(const char *value); -/** TODO: Add new capability that allows skipping of permission checks */ -bool is_internal_service(const char *router); - -/*************************************************************************************** - * TODO: Move the following functions to a header that's internal to the MaxScale core * - ***************************************************************************************/ +/** + * @brief Get worker thread count + * + * @return Number of worker theads + */ +int config_threadcount(void); /** - * @brief Generate default module parameters + * @brief Get number of non-blocking polls * - * Adds any default parameters to @c ctx that aren't already in it. - * - * @param ctx Configuration context where the parameters are added - * @param params Module parameters + * @return Number of non-blocking polls */ -void config_add_defaults(CONFIG_CONTEXT *ctx, const MXS_MODULE_PARAM *params); +unsigned int config_nbpolls(void); -char* config_clean_string_list(const char* str); -CONFIG_PARAMETER* config_clone_param(const CONFIG_PARAMETER* param); -void config_enable_feedback_task(void); -void config_disable_feedback_task(void); -GATEWAY_CONF* config_get_global_options(); -bool config_load(const char *); -unsigned int config_nbpolls(); -unsigned int config_pollsleep(); -bool config_reload(); -int config_threadcount(); -void config_parameter_free(CONFIG_PARAMETER* p1); +/** + * @brief Get poll sleep interval + * + * @return The time each thread waits for a blocking poll + */ +unsigned int config_pollsleep(void); + +/** + * @brief Enable feedback task + */ +void config_enable_feedback_task(void); + +/** + * @brief Disable feedback task + */ +void config_disable_feedback_task(void); + + +/** TODO: Add new capability that allows skipping of permission checks */ +bool is_internal_service(const char *router); + +/** + * @brief Reload the configuration + * + * @return True if reloading was successful + */ +bool config_reload(void); MXS_END_DECLS diff --git a/server/core/config.c b/server/core/config.c index 4fb9bf07a..88578507a 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -66,6 +66,7 @@ #include #include +#include "maxscale/config.h" #include "maxscale/filter.h" #include "maxscale/service.h" @@ -718,8 +719,7 @@ config_load(const char *filename) * * @return True on success, false on fatal error. */ -bool -config_reload() +bool config_reload() { bool rval = false; @@ -2305,11 +2305,6 @@ bool config_append_param(CONFIG_CONTEXT* obj, const char* key, const char* value return rval; } -/** - * Return the pointer to the global options for MaxScale. - * @return Pointer to the GATEWAY_CONF structure. This is a static structure and - * should not be modified. - */ GATEWAY_CONF* config_get_global_options() { return &gateway; diff --git a/server/core/config_runtime.c b/server/core/config_runtime.c index 9e3d4fcef..8326e93a2 100644 --- a/server/core/config_runtime.c +++ b/server/core/config_runtime.c @@ -18,6 +18,7 @@ #include #include +#include "maxscale/config.h" #include "maxscale/service.h" static SPINLOCK crt_lock = SPINLOCK_INIT; diff --git a/server/core/filter.c b/server/core/filter.c index 268eee934..5975001a8 100644 --- a/server/core/filter.c +++ b/server/core/filter.c @@ -34,6 +34,8 @@ #include #include "maxscale/filter.h" +#include "maxscale/config.h" + static SPINLOCK filter_spin = SPINLOCK_INIT; /**< Protects the list of all filters */ static MXS_FILTER_DEF *allFilters = NULL; /**< The list of all filters */ diff --git a/server/core/gateway.cc b/server/core/gateway.cc index 753181f74..23efd52bf 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -70,6 +70,7 @@ #include #include +#include "maxscale/config.h" #include "maxscale/service.h" #include "maxscale/statistics.h" diff --git a/server/core/maxscale/config.h b/server/core/maxscale/config.h new file mode 100644 index 000000000..ebce95952 --- /dev/null +++ b/server/core/maxscale/config.h @@ -0,0 +1,101 @@ +#pragma once +/* + * Copyright (c) 2016 MariaDB Corporation Ab + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file and at www.mariadb.com/bsl. + * + * Change Date: 2019-07-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2 or later of the General + * Public License. + */ + +/** + * @file core/maxscale/config.h - The private config interface + */ + +#include +#include + +MXS_BEGIN_DECLS + +/** + * @brief Generate default module parameters + * + * Adds any default parameters to @c ctx that aren't already in it. + * + * @param ctx Configuration context where the parameters are added + * @param params Module parameters + */ +void config_add_defaults(CONFIG_CONTEXT *ctx, const MXS_MODULE_PARAM *params); + +char* config_clean_string_list(const char* str); +CONFIG_PARAMETER* config_clone_param(const CONFIG_PARAMETER* param); +bool config_load(const char *); +void config_parameter_free(CONFIG_PARAMETER* p1); + +/** + * @brief Creates an empty configuration context + * + * @param section Context name + * @return New context or NULL on memory allocation failure + */ +CONFIG_CONTEXT* config_context_create(const char *section); + +/** + * @brief Free a configuration context + * + * @param context The context to free + */ +void config_context_free(CONFIG_CONTEXT *context); + +/** + * @brief Add a parameter to a configuration context + * + * @param obj Context where the parameter should be added + * @param key Key to add + * @param value Value for the key + * @return True on success, false on memory allocation error + */ +bool config_add_param(CONFIG_CONTEXT* obj, const char* key, const char* value); + +/** + * @brief Append to an existing parameter + * + * @param obj Configuration context + * @param key Parameter name + * @param value Value to append to the parameter + * @return True on success, false on memory allocation error + */ +bool config_append_param(CONFIG_CONTEXT* obj, const char* key, const char* value); + +/** + * @brief Construct an SSL structure + * + * The SSL structure is used by both listeners and servers. + * + * TODO: Rename to something like @c config_construct_ssl + * + * @param obj Configuration context + * @param require_cert Whether certificates are required + * @param error_count Pointer to an int which is incremented for each error + * @return New SSL_LISTENER structure or NULL on error + */ +SSL_LISTENER *make_ssl_structure(CONFIG_CONTEXT *obj, bool require_cert, int *error_count); + +/** + * @brief Check if all SSL parameters are defined + * + * Helper function to check whether all of the required SSL parameters are defined + * in the configuration context. The checked parameters are 'ssl', 'ssl_key', + * 'ssl_cert' and 'ssl_ca_cert'. The 'ssl' parameter must also have a value of + * 'required'. + * + * @param obj Configuration context + * @return True if all required parameters are present + */ +bool config_have_required_ssl_params(CONFIG_CONTEXT *obj); + +MXS_END_DECLS diff --git a/server/core/monitor.c b/server/core/monitor.c index 138f52c31..e45bc8fdd 100644 --- a/server/core/monitor.c +++ b/server/core/monitor.c @@ -42,6 +42,8 @@ #include #include +#include "maxscale/config.h" + static MONITOR *allMonitors = NULL; static SPINLOCK monLock = SPINLOCK_INIT; diff --git a/server/core/service.c b/server/core/service.c index 9d51237a2..012129781 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -66,6 +66,8 @@ #include #include #include + +#include "maxscale/config.h" #include "maxscale/filter.h" #include "maxscale/service.h" diff --git a/server/modules/routing/debugcli/debugcmd.c b/server/modules/routing/debugcli/debugcmd.c index ed15fdfcf..3b23f3e6f 100644 --- a/server/modules/routing/debugcli/debugcmd.c +++ b/server/modules/routing/debugcli/debugcmd.c @@ -1947,7 +1947,7 @@ reload_dbusers(DCB *dcb, SERVICE *service) } /** - * Relaod the configuration data from the config file + * Reload the configuration data from the config file * * @param dcb DCB to use to send output */ diff --git a/server/modules/routing/schemarouter/schemarouter.c b/server/modules/routing/schemarouter/schemarouter.c index 46b19ee22..dc39720fd 100644 --- a/server/modules/routing/schemarouter/schemarouter.c +++ b/server/modules/routing/schemarouter/schemarouter.c @@ -743,14 +743,17 @@ static ROUTER* createInstance(SERVICE *service, char **options) if ((param = config_get_param(conf, "ignore_databases"))) { - char *sptr, *tok, *val = config_clean_string_list(param->value); + char val[strlen(param->value) + 1]; + strcpy(val, param->value); - tok = strtok_r(val, ",", &sptr); + const char *sep = ", \t"; + char *sptr; + char *tok = strtok_r(val, sep, &sptr); while (tok) { hashtable_add(router->ignored_dbs, tok, ""); - tok = strtok_r(NULL, ",", &sptr); + tok = strtok_r(NULL, sep, &sptr); } }