]>
Commit | Line | Data |
---|---|---|
1 | #include "../nick/nick.h" | |
2 | #include "../lib/sstring.h" | |
3 | #include "../parser/parser.h" | |
4 | #include "../channel/channel.h" | |
5 | #include "../lib/flags.h" | |
6 | #include "../authext/authext.h" | |
7 | #include "../patricia/patricia.h" | |
8 | #include "../whowas/whowas.h" | |
9 | ||
10 | #ifndef __NEWSEARCH_H | |
11 | #define __NEWSEARCH_H | |
12 | ||
13 | #define NSMAX_KILL_LIMIT 500 | |
14 | #define NSMAX_GLINE_LIMIT 500 | |
15 | ||
16 | /* gline duration, in seconds */ | |
17 | #define NSGLINE_DURATION 3600 | |
18 | ||
19 | #define NSMAX_REASON_LEN 120 | |
20 | #define NSMAX_NOTICE_LEN 250 | |
21 | #define NSMAX_COMMAND_LEN 20 | |
22 | ||
23 | #define RETURNTYPE_BOOL 0x01 | |
24 | #define RETURNTYPE_INT 0x02 | |
25 | #define RETURNTYPE_STRING 0x03 | |
26 | #define RETURNTYPE_TYPE 0xFF | |
27 | #define RETURNTYPE_CONST 0x100 | |
28 | ||
29 | #define VARIABLE_LEN 10 | |
30 | #define MAX_VARIABLES 10 | |
31 | ||
32 | struct searchNode; | |
33 | struct searchCtx; | |
34 | struct coercedata; | |
35 | ||
36 | typedef struct searchNode *(*searchParseFunc)(struct searchCtx *ctx, char *input); | |
37 | typedef void (*replyFunc)(nick *np, char *format, ...); | |
38 | typedef void (*wallFunc)(int level, char *format, ...); | |
39 | ||
40 | typedef struct searchNode *(*parseFunc)(struct searchCtx *, int, char **); | |
41 | typedef void (*freeFunc)(struct searchCtx *, struct searchNode *); | |
42 | typedef void *(*exeFunc)(struct searchCtx *, struct searchNode *, void *); | |
43 | typedef void (*ChanDisplayFunc)(struct searchCtx *, nick *, chanindex *); | |
44 | typedef void (*NickDisplayFunc)(struct searchCtx *, nick *, nick *); | |
45 | typedef void (*UserDisplayFunc)(struct searchCtx *, nick *, authname *); | |
46 | typedef void (*WhowasDisplayFunc)(struct searchCtx *, nick *, whowas *); | |
47 | typedef void (*HeaderFunc)(void *sender, void *arg); | |
48 | ||
49 | struct coercedata { | |
50 | struct searchNode *child; | |
51 | union { | |
52 | char *stringbuf; | |
53 | unsigned long val; | |
54 | } u; | |
55 | }; | |
56 | ||
57 | typedef struct searchNode { | |
58 | int returntype; | |
59 | exeFunc exe; | |
60 | freeFunc free; | |
61 | void *localdata; | |
62 | } searchNode; | |
63 | ||
64 | struct searchVariable { | |
65 | char name[VARIABLE_LEN]; | |
66 | struct searchNode data; | |
67 | struct coercedata cdata; | |
68 | }; | |
69 | ||
70 | typedef struct searchCmd { | |
71 | void *defaultdisplayfunc; | |
72 | sstring *name; | |
73 | CommandHandler handler; | |
74 | struct CommandTree *outputtree; | |
75 | struct CommandTree *searchtree; | |
76 | } searchCmd; | |
77 | ||
78 | typedef struct searchList { | |
79 | void *cmd; | |
80 | sstring *name; | |
81 | char *help; | |
82 | struct searchList *next; | |
83 | } searchList; | |
84 | ||
85 | typedef struct searchCtx { | |
86 | searchParseFunc parser; | |
87 | replyFunc reply; | |
88 | wallFunc wall; | |
89 | void *arg; | |
90 | struct searchVariable vars[MAX_VARIABLES]; | |
91 | int lastvar; | |
92 | struct searchCmd *searchcmd; | |
93 | nick *sender; | |
94 | int limit; | |
95 | array *targets; | |
96 | void *displayfn; | |
97 | } searchCtx; | |
98 | ||
99 | /* Core functions */ | |
100 | /* Logical (BOOL -> BOOL)*/ | |
101 | struct searchNode *and_parse(searchCtx *ctx, int argc, char **argv); | |
102 | struct searchNode *not_parse(searchCtx *ctx, int argc, char **argv); | |
103 | struct searchNode *or_parse(searchCtx *ctx, int argc, char **argv); | |
104 | ||
105 | /* Comparison (INT -> BOOL) */ | |
106 | struct searchNode *eq_parse(searchCtx *ctx, int argc, char **argv); | |
107 | struct searchNode *lt_parse(searchCtx *ctx, int argc, char **argv); | |
108 | struct searchNode *gt_parse(searchCtx *ctx, int argc, char **argv); | |
109 | ||
110 | /* String match (STRING -> BOOL) */ | |
111 | struct searchNode *match_parse(searchCtx *ctx, int argc, char **argv); | |
112 | struct searchNode *regex_parse(searchCtx *ctx, int argc, char **argv); | |
113 | ||
114 | /* Length (STRING -> INT) */ | |
115 | struct searchNode *length_parse(searchCtx *ctx, int argc, char **argv); | |
116 | ||
117 | /* kill/gline actions (BOOL) */ | |
118 | struct searchNode *kill_parse(searchCtx *ctx, int argc, char **argv); | |
119 | struct searchNode *gline_parse(searchCtx *ctx, int argc, char **argv); | |
120 | ||
121 | /* notice action (BOOL) */ | |
122 | struct searchNode *notice_parse(searchCtx *ctx, int argc, char **argv); | |
123 | ||
124 | /* Nick/Channel functions (various types) */ | |
125 | struct searchNode *nick_parse(searchCtx *ctx, int argc, char **argv); | |
126 | struct searchNode *modes_parse(searchCtx *ctx, int argc, char **argv); | |
127 | ||
128 | /* Nick functions (various types) */ | |
129 | struct searchNode *hostmask_parse(searchCtx *ctx, int argc, char **argv); | |
130 | struct searchNode *realname_parse(searchCtx *ctx, int argc, char **argv); | |
131 | struct searchNode *away_parse(searchCtx *ctx, int argc, char **argv); | |
132 | struct searchNode *authname_parse(searchCtx *ctx, int argc, char **argv); | |
133 | struct searchNode *authts_parse(searchCtx *ctx, int argc, char **argv); | |
134 | struct searchNode *ident_parse(searchCtx *ctx, int argc, char **argv); | |
135 | struct searchNode *host_parse(searchCtx *ctx, int argc, char **argv); | |
136 | struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv); | |
137 | struct searchNode *timestamp_parse(searchCtx *ctx, int argc, char **argv); | |
138 | struct searchNode *country_parse(searchCtx *ctx, int argc, char **argv); | |
139 | struct searchNode *ip_parse(searchCtx *ctx, int argc, char **argv); | |
140 | struct searchNode *channels_parse(searchCtx *ctx, int argc, char **argv); | |
141 | struct searchNode *server_parse(searchCtx *ctx, int argc, char **argv); | |
142 | struct searchNode *authid_parse(searchCtx *ctx, int argc, char **argv); | |
143 | struct searchNode *cidr_parse(searchCtx *ctx, int argc, char **argv); | |
144 | struct searchNode *ipv6_parse(searchCtx *ctx, int argc, char **argv); | |
145 | struct searchNode *message_parse(searchCtx *ctx, int argc, char **argv); | |
146 | ||
147 | /* Whowas functions (various types) */ | |
148 | struct searchNode *quit_parse(searchCtx *ctx, int argc, char **argv); | |
149 | struct searchNode *killed_parse(searchCtx *ctx, int argc, char **argv); | |
150 | struct searchNode *renamed_parse(searchCtx *ctx, int argc, char **argv); | |
151 | struct searchNode *age_parse(searchCtx *ctx, int argc, char **argv); | |
152 | struct searchNode *newnick_parse(searchCtx *ctx, int argc, char **argv); | |
153 | struct searchNode *reason_parse(searchCtx *ctx, int argc, char **argv); | |
154 | ||
155 | /* Channel functions (various types) */ | |
156 | struct searchNode *exists_parse(searchCtx *ctx, int argc, char **argv); | |
157 | struct searchNode *services_parse(searchCtx *ctx, int argc, char **argv); | |
158 | struct searchNode *size_parse(searchCtx *ctx, int argc, char **argv); | |
159 | struct searchNode *name_parse(searchCtx *ctx, int argc, char **argv); | |
160 | struct searchNode *topic_parse(searchCtx *ctx, int argc, char **argv); | |
161 | struct searchNode *oppct_parse(searchCtx *ctx, int argc, char **argv); | |
162 | struct searchNode *cumodecount_parse(searchCtx *ctx, int argc, char **argv); | |
163 | struct searchNode *cumodepct_parse(searchCtx *ctx, int argc, char **argv); | |
164 | struct searchNode *hostpct_parse(searchCtx *ctx, int argc, char **argv); | |
165 | struct searchNode *authedpct_parse(searchCtx *ctx, int argc, char **argv); | |
166 | struct searchNode *kick_parse(searchCtx *ctx, int argc, char **argv); | |
167 | ||
168 | /* Iteration functions */ | |
169 | struct searchNode *any_parse(searchCtx *ctx, int argc, char **argv); | |
170 | struct searchNode *all_parse(searchCtx *ctx, int argc, char **argv); | |
171 | struct searchNode *var_parse(searchCtx *ctx, int argc, char **argv); | |
172 | ||
173 | /* Iteraterable functions */ | |
174 | struct searchNode *channeliter_parse(searchCtx *ctx, int argc, char **argv); | |
175 | struct searchNode *nickiter_parse(searchCtx *ctx, int argc, char **argv); | |
176 | ||
177 | /* Functions that operate on strings */ | |
178 | struct searchNode *cumodes_parse(searchCtx *ctx, int argc, char **argv); | |
179 | ||
180 | /* Force a node to return the thing you want */ | |
181 | struct searchNode *coerceNode(searchCtx *ctx, struct searchNode *thenode, int type); | |
182 | ||
183 | /* Registration functions */ | |
184 | searchCmd *registersearchcommand(char *name, int level, CommandHandler cmd, void *defaultdisplayfunc); | |
185 | void deregistersearchcommand(searchCmd *scmd); | |
186 | void registersearchterm(searchCmd *cmd, char *term, parseFunc parsefunc, int level, char *help); | |
187 | void deregistersearchterm(searchCmd *cmd, char *term, parseFunc parsefunc); | |
188 | ||
189 | void registerglobalsearchterm(char *term, parseFunc parsefunc, char *help); | |
190 | void deregisterglobalsearchterm(char *term, parseFunc parsefunc); | |
191 | ||
192 | void regdisp( searchCmd *cmd, const char *name, void *handler, int level, char *help); | |
193 | void unregdisp( searchCmd *cmd, const char *name, void *handler); | |
194 | ||
195 | /* Special nick* printf */ | |
196 | void nssnprintf(char *, size_t, const char *, nick *); | |
197 | ||
198 | void displaystrerror(replyFunc reply, nick *np, const char *input); | |
199 | ||
200 | extern const char *parseError; | |
201 | extern nick *senderNSExtern; | |
202 | ||
203 | void printnick(searchCtx *, nick *, nick *); | |
204 | void printuser(searchCtx *, nick *, authname *); | |
205 | void printchannel(searchCtx *, nick *, chanindex *); | |
206 | void printwhowas(searchCtx *, nick *, whowas *); | |
207 | ||
208 | void nicksearch_exe(struct searchNode *search, searchCtx *sctx); | |
209 | void chansearch_exe(struct searchNode *search, searchCtx *sctx); | |
210 | void usersearch_exe(struct searchNode *search, searchCtx *ctx); | |
211 | void whowassearch_exe(struct searchNode *search, searchCtx *ctx); | |
212 | ||
213 | int do_nicksearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); | |
214 | int do_chansearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); | |
215 | int do_usersearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); | |
216 | int do_whowassearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); | |
217 | ||
218 | void *literal_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); | |
219 | void literal_free(searchCtx *ctx, struct searchNode *thenode); | |
220 | ||
221 | struct searchVariable *var_register(searchCtx *ctx, char *arg, int type); | |
222 | searchNode *var_get(searchCtx *ctx, char *arg); | |
223 | void var_setstr(struct searchVariable *v, char *data); | |
224 | ||
225 | void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc replyfn, wallFunc wallfn, void *arg, searchCmd *cmd, nick *sender, void *displayfn, int limit, array *targets); | |
226 | ||
227 | /* AST functions */ | |
228 | ||
229 | struct searchASTNode; | |
230 | ||
231 | #define AST_NODE_CHILD 1 | |
232 | #define AST_NODE_LITERAL 2 | |
233 | ||
234 | /* items to store in the ast lookup cache */ | |
235 | #define AST_RECENT 10 | |
236 | ||
237 | struct searchASTExpr; | |
238 | ||
239 | typedef struct searchASTNode { | |
240 | parseFunc fn; | |
241 | int argc; | |
242 | struct searchASTExpr *argv; | |
243 | } searchASTNode; | |
244 | ||
245 | typedef struct searchASTExpr { | |
246 | int type; | |
247 | union { | |
248 | char *literal; | |
249 | /* this was originally a pointer, but having it as one means you can't memcpy directly */ | |
250 | struct searchASTNode child; | |
251 | } u; | |
252 | } searchASTExpr; | |
253 | ||
254 | typedef struct searchASTCache { | |
255 | searchASTExpr *tree; | |
256 | searchASTExpr *cache[AST_RECENT]; | |
257 | int nextpos; | |
258 | } searchASTCache; | |
259 | ||
260 | #define __NSASTSizeOfArray(x) (sizeof(x) / sizeof(x[0])) | |
261 | ||
262 | #define __NSASTExpr(x, y, ...) (searchASTExpr){.type = x, .u.y = __VA_ARGS__} | |
263 | #define __NSASTRawNode(x, c, y) (searchASTNode){.fn = x, .argc = c, .argv = y} | |
264 | ||
265 | #define __NSASTSizeNode(x, y) __NSASTRawNode(x, __NSASTSizeOfArray(y), y) | |
266 | #define __NSASTNode(x, ...) __NSASTSizeNode(x, ((searchASTExpr []){__VA_ARGS__})) | |
267 | ||
268 | #define __NSASTChild(...) __NSASTExpr(AST_NODE_CHILD, child, __VA_ARGS__) | |
269 | ||
270 | #define NSASTLiteral(value) __NSASTExpr(AST_NODE_LITERAL, literal, value) | |
271 | #define NSASTNode(fn, ...) __NSASTChild(__NSASTNode(fn, __VA_ARGS__)) | |
272 | #define NSASTManualNode(fn, count, children) __NSASTChild(__NSASTRawNode(fn, count, children)) | |
273 | ||
274 | searchNode *search_astparse(searchCtx *, char *); | |
275 | ||
276 | int ast_nicksearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, NickDisplayFunc display, HeaderFunc header, void *headerarg, int limit, array *); | |
277 | int ast_chansearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, ChanDisplayFunc display, HeaderFunc header, void *headerarg, int limit, array *); | |
278 | int ast_usersearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, UserDisplayFunc display, HeaderFunc header, void *headerarg, int limit, array *); | |
279 | int ast_whowassearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, WhowasDisplayFunc display, HeaderFunc header, void *headerarg, int limit, array *); | |
280 | ||
281 | char *ast_printtree(char *buf, size_t bufsize, searchASTExpr *expr, searchCmd *cmd); | |
282 | ||
283 | int parseopts(int cargc, char **cargv, int *arg, int *limit, void **subset, void *display, CommandTree *sl, replyFunc reply, void *sender); | |
284 | ||
285 | typedef int (*ASTFunc)(searchASTExpr *, replyFunc, void *, wallFunc, void *, HeaderFunc, void *, int limit, array *targets); | |
286 | ||
287 | /* erk */ | |
288 | extern searchList *globalterms; | |
289 | ||
290 | extern searchCmd *reg_nicksearch; | |
291 | extern searchCmd *reg_chansearch; | |
292 | extern searchCmd *reg_usersearch; | |
293 | extern searchCmd *reg_whowassearch; | |
294 | ||
295 | extern UserDisplayFunc defaultuserfn; | |
296 | extern NickDisplayFunc defaultnickfn; | |
297 | extern ChanDisplayFunc defaultchanfn; | |
298 | extern WhowasDisplayFunc defaultwhowasfn; | |
299 | ||
300 | struct searchNode *argtoconststr(char *command, searchCtx *ctx, char *arg, char **p); | |
301 | ||
302 | #endif |