Expose module mapping function
The effective name of a module can now be obtained also outside the module loading mechanism.
This commit is contained in:
@ -151,4 +151,17 @@ json_t* module_to_json(const MXS_MODULE* module, const char* host);
|
|||||||
*/
|
*/
|
||||||
json_t* module_list_to_json(const char* host);
|
json_t* module_list_to_json(const char* host);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return effective module name.
|
||||||
|
*
|
||||||
|
* The effective module name is the actual name of a module. In case
|
||||||
|
* a module has been renamed (and the old name deprecated), the effective
|
||||||
|
* name of a module may be different from the used one.
|
||||||
|
*
|
||||||
|
* @param name The name of a module.
|
||||||
|
*
|
||||||
|
* @return The effective name (may be the same).
|
||||||
|
*/
|
||||||
|
const char* mxs_module_get_effective_name(const char* name);
|
||||||
|
|
||||||
MXS_END_DECLS
|
MXS_END_DECLS
|
||||||
|
@ -66,37 +66,6 @@ static NAME_MAPPING name_mappings[] =
|
|||||||
|
|
||||||
static const size_t N_NAME_MAPPINGS = sizeof(name_mappings) / sizeof(name_mappings[0]);
|
static const size_t N_NAME_MAPPINGS = sizeof(name_mappings) / sizeof(name_mappings[0]);
|
||||||
|
|
||||||
static const char* get_effective_name(const char* name)
|
|
||||||
{
|
|
||||||
const char* effective_name = NULL;
|
|
||||||
size_t i = 0;
|
|
||||||
|
|
||||||
while (!effective_name && (i < N_NAME_MAPPINGS))
|
|
||||||
{
|
|
||||||
NAME_MAPPING& nm = name_mappings[i];
|
|
||||||
|
|
||||||
if (strcasecmp(name, nm.from) == 0)
|
|
||||||
{
|
|
||||||
if (!nm.warned)
|
|
||||||
{
|
|
||||||
MXS_WARNING("%s module '%s' has been deprecated, use '%s' instead.",
|
|
||||||
nm.type, nm.from, nm.to);
|
|
||||||
nm.warned = true;
|
|
||||||
}
|
|
||||||
effective_name = nm.to;
|
|
||||||
}
|
|
||||||
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!effective_name)
|
|
||||||
{
|
|
||||||
effective_name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return effective_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
static LOADED_MODULE *registered = NULL;
|
static LOADED_MODULE *registered = NULL;
|
||||||
|
|
||||||
static LOADED_MODULE *find_module(const char *module);
|
static LOADED_MODULE *find_module(const char *module);
|
||||||
@ -166,7 +135,7 @@ void *load_module(const char *module, const char *type)
|
|||||||
ss_dassert(module && type);
|
ss_dassert(module && type);
|
||||||
LOADED_MODULE *mod;
|
LOADED_MODULE *mod;
|
||||||
|
|
||||||
module = get_effective_name(module);
|
module = mxs_module_get_effective_name(module);
|
||||||
|
|
||||||
if ((mod = find_module(module)) == NULL)
|
if ((mod = find_module(module)) == NULL)
|
||||||
{
|
{
|
||||||
@ -222,7 +191,7 @@ void *load_module(const char *module, const char *type)
|
|||||||
|
|
||||||
void unload_module(const char *module)
|
void unload_module(const char *module)
|
||||||
{
|
{
|
||||||
module = get_effective_name(module);
|
module = mxs_module_get_effective_name(module);
|
||||||
|
|
||||||
LOADED_MODULE *mod = find_module(module);
|
LOADED_MODULE *mod = find_module(module);
|
||||||
|
|
||||||
@ -616,7 +585,7 @@ RESULTSET *moduleGetList()
|
|||||||
|
|
||||||
const MXS_MODULE *get_module(const char *name, const char *type)
|
const MXS_MODULE *get_module(const char *name, const char *type)
|
||||||
{
|
{
|
||||||
name = get_effective_name(name);
|
name = mxs_module_get_effective_name(name);
|
||||||
|
|
||||||
LOADED_MODULE *mod = find_module(name);
|
LOADED_MODULE *mod = find_module(name);
|
||||||
|
|
||||||
@ -669,3 +638,34 @@ MXS_MODULE* mxs_module_iterator_get_next(MXS_MODULE_ITERATOR* iterator)
|
|||||||
|
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* mxs_module_get_effective_name(const char* name)
|
||||||
|
{
|
||||||
|
const char* effective_name = NULL;
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
while (!effective_name && (i < N_NAME_MAPPINGS))
|
||||||
|
{
|
||||||
|
NAME_MAPPING& nm = name_mappings[i];
|
||||||
|
|
||||||
|
if (strcasecmp(name, nm.from) == 0)
|
||||||
|
{
|
||||||
|
if (!nm.warned)
|
||||||
|
{
|
||||||
|
MXS_WARNING("%s module '%s' has been deprecated, use '%s' instead.",
|
||||||
|
nm.type, nm.from, nm.to);
|
||||||
|
nm.warned = true;
|
||||||
|
}
|
||||||
|
effective_name = nm.to;
|
||||||
|
}
|
||||||
|
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!effective_name)
|
||||||
|
{
|
||||||
|
effective_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return effective_name;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user