Add automatically compiled PCRE2_REGEX config parameter type
The regex strings are compiled automatically. During file parsing, the string is compiled once using default settings to check that the pattern is valid. Once a module asks for the compiled pcre2_code, the pattern is compiled again with module given settings. The regex string in the config file should be enclosed within '/ ... /'
This commit is contained in:
@ -24,6 +24,7 @@
|
||||
|
||||
#include <maxscale/modinfo.h>
|
||||
#include <maxscale/jansson.h>
|
||||
#include <maxscale/pcre2.h>
|
||||
|
||||
MXS_BEGIN_DECLS
|
||||
|
||||
@ -352,12 +353,40 @@ struct server* config_get_server(const MXS_CONFIG_PARAMETER *params, const char
|
||||
int config_get_server_list(const MXS_CONFIG_PARAMETER *params, const char *key,
|
||||
struct server*** output);
|
||||
|
||||
/**
|
||||
* Get a compiled regular expression. The returned @c pcre2_code should be freed
|
||||
* by the caller.
|
||||
*
|
||||
* @param params List of configuration parameters
|
||||
* @param key Parameter name
|
||||
* @param options PCRE2 compilation options
|
||||
* @return The compiled PCRE2 code, or NULL on error
|
||||
*/
|
||||
pcre2_code* config_get_compiled_regex(const MXS_CONFIG_PARAMETER *params, const char *key,
|
||||
uint32_t options);
|
||||
|
||||
/**
|
||||
* Get a compiled regular expression and the capture count of the pattern. The
|
||||
* @c pcre2_code should be freed by the caller.
|
||||
*
|
||||
* @param params List of configuration parameters
|
||||
* @param key Parameter name
|
||||
* @param options PCRE2 compilation options
|
||||
* @param output_code Output for compilation result
|
||||
* @param output_capcount Output for capture count
|
||||
* @return True on success, false otherwise
|
||||
*/
|
||||
bool config_get_compiled_regex_capcount(const MXS_CONFIG_PARAMETER *params,
|
||||
const char *key, uint32_t options,
|
||||
pcre2_code** output_code,
|
||||
uint32_t* output_capcount);
|
||||
|
||||
/**
|
||||
* Parse a list of server names and write the results in an array of strings
|
||||
* with one server name in each. The output array and its elements should be
|
||||
* deallocated by the caller. The server names are not checked to be actual
|
||||
* configured servers.
|
||||
*
|
||||
*
|
||||
* The output array may contain more elements than the the value returned, but these
|
||||
* extra elements are null and in the end of the array. If no server names were
|
||||
* parsed or if an error occurs, nothing is written to the output parameter.
|
||||
|
@ -84,7 +84,8 @@ enum mxs_module_param_type
|
||||
MXS_MODULE_PARAM_PATH, /**< Path to a file or a directory */
|
||||
MXS_MODULE_PARAM_SERVICE, /**< Service name */
|
||||
MXS_MODULE_PARAM_SERVER, /**< Server name */
|
||||
MXS_MODULE_PARAM_SERVERLIST /**< List of server names, separated by ',' */
|
||||
MXS_MODULE_PARAM_SERVERLIST, /**< List of server names, separated by ',' */
|
||||
MXS_MODULE_PARAM_REGEX /**< A regex string enclosed in '/' */
|
||||
};
|
||||
|
||||
/** Maximum and minimum values for integer types */
|
||||
@ -246,6 +247,8 @@ static inline const char* mxs_module_param_type_to_string(enum mxs_module_param_
|
||||
return "server";
|
||||
case MXS_MODULE_PARAM_SERVERLIST:
|
||||
return "serverlist";
|
||||
case MXS_MODULE_PARAM_REGEX:
|
||||
return "regular expression";
|
||||
default:
|
||||
ss_dassert(!true);
|
||||
return "unknown";
|
||||
|
Reference in New Issue
Block a user