summaryrefslogtreecommitdiff
path: root/include/aho-corasick.h
blob: a468256c314ddc0edd5e8526ee2173a3fda8a0da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);