2 * ModSecurity for Apache 2.x, http://www.modsecurity.org/
3 * Copyright (c) 2004-2009 Breach Security, Inc. (http://www.breach.com/)
5 * This product is released under the terms of the General Public Licence,
6 * version 2 (GPLv2). Please refer to the file LICENSE (included with this
7 * distribution) which contains the complete text of the licence.
9 * There are special exceptions to the terms and conditions of the GPL
10 * as it is applied to this software. View the full text of the exception in
11 * file MODSECURITY_LICENSING_EXCEPTION in the directory of this software
14 * If any of the files related to licensing are missing or if you have any
15 * other questions related to licensing please contact Breach Security, Inc.
16 * directly using the email address support@breach.com.
23 #include <apr_pools.h>
25 #define ACMP_FLAG_BYTE 0
26 #define ACMP_FLAG_CASE_SENSITIVE 1
27 #define ACMP_FLAG_CASE_INSENSITIVE 0
29 #define ACMP_FLAG_UTF8 0x100
33 * Opaque struct with parser data
35 typedef struct ACMP ACMP;
38 * Used to separate state from the trie for acmp_process_quick function
46 * Callback function. Arguments are:
47 * ACMP * - acmp parser that initiated callback
48 * void * - custom data you supplied when adding callback
49 * apr_size_t - position in bytes where pattern was found
50 * apr_size_t - position in chars where pattern was found, for multibyte strings
52 typedef void (*acmp_callback_t)(ACMP *, void *, apr_size_t, apr_size_t);
55 * flags - OR-ed values of ACMP_FLAG constants
56 * pool - apr_pool to use as parent pool, can be set to NULL
58 ACMP *acmp_create(int flags, apr_pool_t *pool);
61 * Destroys previously created parser
63 void acmp_destroy(ACMP *parser);
66 * Creates parser with same options and same patterns
67 * parser - ACMP parser to duplicate
68 * pool - parent pool to use, if left as NULL original parser's parent pool is used
70 ACMP *acmp_duplicate(ACMP *parser, apr_pool_t *pool);
73 * Adds pattern to parser. Cannot be done after starting the search.
74 * parser - ACMP parser
75 * pattern - string with pattern to match
76 * callback - Optional, pointer to an acmp_callback_t function
77 * data - pointer to data that will be passed to callback function, only used if callback
79 * len - Length of pattern in characters, if zero string length is used.
81 apr_status_t acmp_add_pattern(ACMP *parser, const char *pattern,
82 acmp_callback_t callback, void *data, apr_size_t len);
85 * Called to process incoming data stream. You must call acmp_done after sending
88 * data - ptr to incoming data
89 * len - size of data in bytes
91 apr_status_t acmp_process(ACMP *parser, const char *data, apr_size_t len);
94 * Returns number of matches on all patterns combined
96 apr_size_t acmp_match_count_total(ACMP *parser);
99 * Returns number of matches for given pattern
101 apr_size_t acmp_match_count(ACMP *parser, const char *pattern);
104 * Resets the state of parser so you can start using it with new set of data,
105 * or add new patterns.
107 void acmp_reset(ACMP *parser);
110 * Creates an ACMPT struct that will use parser's tree, without duplicating its data
112 ACMPT *acmp_duplicate_quick(ACMP *parser, apr_pool_t *pool);
115 * Process the data using ACMPT to keep state, and ACMPT's parser to keep the tree
117 apr_status_t acmp_process_quick(ACMPT *acmpt, const char **match, const char *data, apr_size_t len);
120 * Prepares parser for searching
122 apr_status_t acmp_prepare(ACMP *parser);