Go to the source code of this file.
Data Structures | |
struct | RegexCombineCtx |
Struct to hold the tree formed by prefix-combining the regexes. More... | |
Functions | |
static int | c2i (char c, int size) |
Char 2 int. More... | |
static void | debugctx (struct RegexCombineCtx *ctx, int level) |
Printf the combined regex ctx. More... | |
static void | regex_add (struct RegexCombineCtx *ctx, const char *regex) |
Add a single regex to a context, combining with existing regex by-prefix. More... | |
static struct RegexCombineCtx * | new_regex_ctx (unsigned int alphabet_size) |
Create and initialize a new RegexCombineCtx. More... | |
static void | move_children (struct RegexCombineCtx *dst, const struct RegexCombineCtx *src) |
static char * | regex_combine (struct RegexCombineCtx *ctx) |
Extract a string from all prefix-combined regexes. More... | |
static unsigned int | get_prefix_length (const char *s1, const char *s2) |
Get the number of matching characters on the prefix of both strings. More... | |
static struct RegexCombineCtx * | get_longest_prefix (struct RegexCombineCtx *ctx, const char *regex) |
Return the child context with the longest prefix match with the regex. More... | |
static void | regex_add_multiple (struct RegexCombineCtx *ctx, const char *regex, struct RegexCombineCtx **children) |
static void | regex_split (struct RegexCombineCtx *ctx, unsigned int len, unsigned int prefix_l) |
Add a single regex to a context, splitting the existing state. More... | |
static void | regex_ctx_destroy (struct RegexCombineCtx *ctx) |
Free all resources used by the context node and all its children. More... | |
char * | REGEX_TEST_combine (char *const regexes[], unsigned int alphabet_size) |
Combine an array of regexes into a single prefix-shared regex. More... | |
char ** | REGEX_TEST_read_from_file (const char *filename) |
Read a set of regexes from a file, one per line and return them in an array suitable for REGEX_TEST_combine. More... | |
void | REGEX_TEST_free_from_file (char **regexes) |
Free all memory reserved for a set of regexes created by read_from_file. More... | |
|
static |
Char 2 int.
Convert a character into its int value depending on the base used
c | Char |
size | base (2, 8 or 16(hex)) |
Definition at line 65 of file regex_test_lib.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, and size.
Referenced by debugctx(), regex_add(), regex_add_multiple(), and regex_split().
|
static |
Printf the combined regex ctx.
ctx | The ctx to printf |
level | Indentation level to start with |
Definition at line 120 of file regex_test_lib.c.
References c2i(), ctx, and debugctx().
Referenced by debugctx(), and REGEX_TEST_combine().
|
static |
Add a single regex to a context, combining with existing regex by-prefix.
ctx | Context with 0 or more regexes. |
regex | Regex to add. |
Definition at line 444 of file regex_test_lib.c.
References c2i(), ctx, get_longest_prefix(), get_prefix_length(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_strdup, new_regex_ctx(), p, regex_add(), regex_add_multiple(), regex_split(), and RegexCombineCtx::s.
Referenced by regex_add(), and REGEX_TEST_combine().
|
static |
Create and initialize a new RegexCombineCtx.
alphabet_size | Size of the alphabet (and the Trie array) |
Definition at line 160 of file regex_test_lib.c.
References ctx, GNUNET_malloc, and GNUNET_new.
Referenced by regex_add(), regex_add_multiple(), regex_split(), and REGEX_TEST_combine().
|
static |
Definition at line 175 of file regex_test_lib.c.
References RegexCombineCtx::children, GNUNET_memcpy, and RegexCombineCtx::size.
Referenced by regex_split().
|
static |
Extract a string from all prefix-combined regexes.
ctx | Context with 0 or more regexes. |
Definition at line 199 of file regex_test_lib.c.
References ctx, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_strdup, GNUNET_YES, p, regex_combine(), and RegexCombineCtx::s.
Referenced by regex_combine(), and REGEX_TEST_combine().
|
static |
Get the number of matching characters on the prefix of both strings.
s1 | String 1. |
s2 | String 2. |
Definition at line 273 of file regex_test_lib.c.
Referenced by get_longest_prefix(), and regex_add().
|
static |
Return the child context with the longest prefix match with the regex.
Usually only one child will match, search all just in case.
ctx | Context whose children to search. |
regex | String to match. |
Definition at line 303 of file regex_test_lib.c.
References ctx, get_prefix_length(), GNUNET_break, and p.
Referenced by regex_add().
|
static |
Definition at line 333 of file regex_test_lib.c.
References c2i(), RegexCombineCtx::children, ctx, GNUNET_assert, GNUNET_memcpy, GNUNET_strdup, new_regex_ctx(), and RegexCombineCtx::s.
Referenced by regex_add(), and regex_split().
|
static |
Add a single regex to a context, splitting the existing state.
We only had a partial match, split existing state, truncate the current node so it only contains the prefix, add suffix(es) as children.
ctx | Context to split. |
len | Length of ctx->s |
prefix_l | Length of common prefix of the new regex and ctx->s |
Definition at line 395 of file regex_test_lib.c.
References c2i(), ctx, GNUNET_free, GNUNET_malloc, GNUNET_strlcpy(), move_children(), new_regex_ctx(), regex_add_multiple(), and RegexCombineCtx::s.
Referenced by regex_add().
|
static |
Free all resources used by the context node and all its children.
ctx | Context to free. |
Definition at line 513 of file regex_test_lib.c.
References ctx, GNUNET_free, and regex_ctx_destroy().
Referenced by regex_ctx_destroy(), and REGEX_TEST_combine().
char * REGEX_TEST_combine | ( | char *const | regexes[], |
unsigned int | alphabet_size | ||
) |
Combine an array of regexes into a single prefix-shared regex.
Returns a prefix-combine regex that matches the same strings as any of the original regexes.
WARNING: only useful for reading specific regexes for specific applications, namely the gnunet-regex-profiler / gnunet-regex-daemon. This function DOES NOT support arbitrary regex combining.
regexes | A NULL-terminated array of regexes. |
alphabet_size | Size of the alphabet the regex uses. |
Definition at line 545 of file regex_test_lib.c.
References ctx, debugctx(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, new_regex_ctx(), regex_add(), regex_combine(), and regex_ctx_destroy().
Referenced by main(), and run().
char ** REGEX_TEST_read_from_file | ( | const char * | filename | ) |
Read a set of regexes from a file, one per line and return them in an array suitable for REGEX_TEST_combine.
The array must be free'd using REGEX_TEST_free_from_file.
filename | Name of the file containing the regexes. |
Definition at line 581 of file regex_test_lib.c.
References removetrailingwhitespace::f, filename, GNUNET_array_grow, GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_handle_size(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_OK, GNUNET_realloc, and size.
Referenced by main(), and run().
void REGEX_TEST_free_from_file | ( | char ** | regexes | ) |
Free all memory reserved for a set of regexes created by read_from_file.
regexes | NULL-terminated array of regexes. |
Definition at line 652 of file regex_test_lib.c.
References GNUNET_free.
Referenced by main(), and run().