[NETFILTER]: bridge-netfilter: remove deferred hooks
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / linux / textsearch.h
blob004808a6df1d080f8389cf2a57f1d4c85ff7673d
1 #ifndef __LINUX_TEXTSEARCH_H
2 #define __LINUX_TEXTSEARCH_H
4 #ifdef __KERNEL__
6 #include <linux/types.h>
7 #include <linux/list.h>
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/err.h>
11 #include <linux/slab.h>
13 struct ts_config;
15 /**
16 * TS_AUTOLOAD - Automatically load textsearch modules when needed
18 #define TS_AUTOLOAD 1
20 /**
21 * struct ts_state - search state
22 * @offset: offset for next match
23 * @cb: control buffer, for persistent variables of get_next_block()
25 struct ts_state
27 unsigned int offset;
28 char cb[40];
31 /**
32 * struct ts_ops - search module operations
33 * @name: name of search algorithm
34 * @init: initialization function to prepare a search
35 * @find: find the next occurrence of the pattern
36 * @destroy: destroy algorithm specific parts of a search configuration
37 * @get_pattern: return head of pattern
38 * @get_pattern_len: return length of pattern
39 * @owner: module reference to algorithm
41 struct ts_ops
43 const char *name;
44 struct ts_config * (*init)(const void *, unsigned int, gfp_t);
45 unsigned int (*find)(struct ts_config *,
46 struct ts_state *);
47 void (*destroy)(struct ts_config *);
48 void * (*get_pattern)(struct ts_config *);
49 unsigned int (*get_pattern_len)(struct ts_config *);
50 struct module *owner;
51 struct list_head list;
54 /**
55 * struct ts_config - search configuration
56 * @ops: operations of chosen algorithm
57 * @get_next_block: callback to fetch the next block to search in
58 * @finish: callback to finalize a search
60 struct ts_config
62 struct ts_ops *ops;
64 /**
65 * get_next_block - fetch next block of data
66 * @consumed: number of bytes consumed by the caller
67 * @dst: destination buffer
68 * @conf: search configuration
69 * @state: search state
71 * Called repeatedly until 0 is returned. Must assign the
72 * head of the next block of data to &*dst and return the length
73 * of the block or 0 if at the end. consumed == 0 indicates
74 * a new search. May store/read persistent values in state->cb.
76 unsigned int (*get_next_block)(unsigned int consumed,
77 const u8 **dst,
78 struct ts_config *conf,
79 struct ts_state *state);
81 /**
82 * finish - finalize/clean a series of get_next_block() calls
83 * @conf: search configuration
84 * @state: search state
86 * Called after the last use of get_next_block(), may be used
87 * to cleanup any leftovers.
89 void (*finish)(struct ts_config *conf,
90 struct ts_state *state);
93 /**
94 * textsearch_next - continue searching for a pattern
95 * @conf: search configuration
96 * @state: search state
98 * Continues a search looking for more occurrences of the pattern.
99 * textsearch_find() must be called to find the first occurrence
100 * in order to reset the state.
102 * Returns the position of the next occurrence of the pattern or
103 * UINT_MAX if not match was found.
105 static inline unsigned int textsearch_next(struct ts_config *conf,
106 struct ts_state *state)
108 unsigned int ret = conf->ops->find(conf, state);
110 if (conf->finish)
111 conf->finish(conf, state);
113 return ret;
117 * textsearch_find - start searching for a pattern
118 * @conf: search configuration
119 * @state: search state
121 * Returns the position of first occurrence of the pattern or
122 * UINT_MAX if no match was found.
124 static inline unsigned int textsearch_find(struct ts_config *conf,
125 struct ts_state *state)
127 state->offset = 0;
128 return textsearch_next(conf, state);
132 * textsearch_get_pattern - return head of the pattern
133 * @conf: search configuration
135 static inline void *textsearch_get_pattern(struct ts_config *conf)
137 return conf->ops->get_pattern(conf);
141 * textsearch_get_pattern_len - return length of the pattern
142 * @conf: search configuration
144 static inline unsigned int textsearch_get_pattern_len(struct ts_config *conf)
146 return conf->ops->get_pattern_len(conf);
149 extern int textsearch_register(struct ts_ops *);
150 extern int textsearch_unregister(struct ts_ops *);
151 extern struct ts_config *textsearch_prepare(const char *, const void *,
152 unsigned int, gfp_t, int);
153 extern void textsearch_destroy(struct ts_config *conf);
154 extern unsigned int textsearch_find_continuous(struct ts_config *,
155 struct ts_state *,
156 const void *, unsigned int);
159 #define TS_PRIV_ALIGNTO 8
160 #define TS_PRIV_ALIGN(len) (((len) + TS_PRIV_ALIGNTO-1) & ~(TS_PRIV_ALIGNTO-1))
162 static inline struct ts_config *alloc_ts_config(size_t payload,
163 gfp_t gfp_mask)
165 struct ts_config *conf;
167 conf = kmalloc(TS_PRIV_ALIGN(sizeof(*conf)) + payload, gfp_mask);
168 if (conf == NULL)
169 return ERR_PTR(-ENOMEM);
171 memset(conf, 0, TS_PRIV_ALIGN(sizeof(*conf)) + payload);
172 return conf;
175 static inline void *ts_config_priv(struct ts_config *conf)
177 return ((u8 *) conf + TS_PRIV_ALIGN(sizeof(struct ts_config)));
180 #endif /* __KERNEL__ */
182 #endif