Imported Upstream version 2.5.11
[libapache-mod-security.git] / apache2 / acmp.h
1 /*
2  * ModSecurity for Apache 2.x, http://www.modsecurity.org/
3  * Copyright (c) 2004-2009 Breach Security, Inc. (http://www.breach.com/)
4  *
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.
8  *
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
12  * distribution.
13  *
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.
17  *
18  */
19 #ifndef ACMP_H_
20 #define ACMP_H_
21
22 #include <apr.h>
23 #include <apr_pools.h>
24
25 #define ACMP_FLAG_BYTE               0
26 #define ACMP_FLAG_CASE_SENSITIVE     1
27 #define ACMP_FLAG_CASE_INSENSITIVE   0
28 #ifdef ACMP_USE_UTF8
29 #define ACMP_FLAG_UTF8               0x100
30 #endif
31
32 /**
33  * Opaque struct with parser data
34  */
35 typedef struct ACMP ACMP;
36
37 /**
38  * Used to separate state from the trie for acmp_process_quick function
39  */
40 typedef struct {
41     ACMP *parser;
42     void *ptr;
43 } ACMPT;
44
45 /**
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
51  */
52 typedef void (*acmp_callback_t)(ACMP *, void *, apr_size_t, apr_size_t);
53
54 /**
55  * flags - OR-ed values of ACMP_FLAG constants
56  * pool  - apr_pool to use as parent pool, can be set to NULL
57  */
58 ACMP *acmp_create(int flags, apr_pool_t *pool);
59
60 /**
61  * Destroys previously created parser
62  */
63 void acmp_destroy(ACMP *parser);
64
65 /**
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
69  */
70 ACMP *acmp_duplicate(ACMP *parser, apr_pool_t *pool);
71
72 /**
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
78  *   is supplied
79  * len - Length of pattern in characters, if zero string length is used.
80  */
81 apr_status_t acmp_add_pattern(ACMP *parser, const char *pattern,
82     acmp_callback_t callback, void *data, apr_size_t len);
83
84 /**
85  * Called to process incoming data stream. You must call acmp_done after sending
86  *   last data packet
87  *
88  * data - ptr to incoming data
89  * len  - size of data in bytes
90  */
91 apr_status_t acmp_process(ACMP *parser, const char *data, apr_size_t len);
92
93 /**
94  * Returns number of matches on all patterns combined
95  */
96 apr_size_t acmp_match_count_total(ACMP *parser);
97
98 /**
99  * Returns number of matches for given pattern
100  */
101 apr_size_t acmp_match_count(ACMP *parser, const char *pattern);
102
103 /**
104  * Resets the state of parser so you can start using it with new set of data,
105  * or add new patterns.
106  */
107 void acmp_reset(ACMP *parser);
108
109 /**
110  * Creates an ACMPT struct that will use parser's tree, without duplicating its data
111  */
112 ACMPT *acmp_duplicate_quick(ACMP *parser, apr_pool_t *pool);
113
114 /**
115  * Process the data using ACMPT to keep state, and ACMPT's parser to keep the tree
116  */
117 apr_status_t acmp_process_quick(ACMPT *acmpt, const char **match, const char *data, apr_size_t len);
118
119 /**
120  * Prepares parser for searching
121  */
122 apr_status_t acmp_prepare(ACMP *parser);
123
124
125 #endif /*ACMP_H_*/