diff options
| author | daniel <daniel@planethacker.net> | 2025-05-06 16:57:32 -0700 |
|---|---|---|
| committer | daniel <daniel@planethacker.net> | 2025-05-06 16:57:32 -0700 |
| commit | 2278df1493e064c197913e49b5d1935942d83448 (patch) | |
| tree | 42f06ab2f76e2ddf228bafbb03f79621975a4534 /include/aho-corasick.h | |
initial import
Diffstat (limited to 'include/aho-corasick.h')
| -rw-r--r-- | include/aho-corasick.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/include/aho-corasick.h b/include/aho-corasick.h new file mode 100644 index 0000000..a468256 --- /dev/null +++ b/include/aho-corasick.h @@ -0,0 +1,30 @@ +#pragma once + +#include <stddef.h> +#include <stdint.h> + +#define AC_BUF_SIZE 65536 +#define AC_ALPHABET_SIZE 256 + +// forward declaration to allow users to define context +struct ac_context; + +typedef struct ac_match { + const char *id; + size_t offset; + size_t len; +} ac_match_t; + +typedef struct ac_context ac_context_t; +typedef struct pattern_node ac_node_t; +typedef struct pattern_entry ac_pattern_t; + +typedef void (*ac_callback)(const ac_match_t *match, void *user_data); + +ac_context_t *ac_new(void); +void ac_free(ac_context_t *ctx); +int ac_add_pattern(ac_context_t *ctx, const char *id, const uint8_t *pattern, size_t len); +int ac_build(ac_context_t *ctx); +int ac_match(ac_context_t *ctx, const uint8_t *data, size_t len, ac_callback cb, void *user_data); +int ac_match_fd(ac_context_t *ctx, int fd, ac_callback cb, void *user_data); +int ac_match_path(ac_context_t *ctx, const char *path, ac_callback cb, void *user_data); |
