]>
Commit | Line | Data |
---|---|---|
16cc6e32 | 1 | #include "../nick/nick.h" |
a92bb8e1 | 2 | #include "../lib/sstring.h" |
56a84a81 IB |
3 | #include "../parser/parser.h" |
4 | #include "../channel/channel.h" | |
5 | #include "../lib/flags.h" | |
e8ad630b | 6 | #include "../authext/authext.h" |
a92bb8e1 | 7 | #include "../patricia/patricia.h" |
0eb4cbd3 | 8 | #include "../whowas/whowas.h" |
c86edd1d | 9 | |
1188d606 P |
10 | #ifndef __NEWSEARCH_H |
11 | #define __NEWSEARCH_H | |
12 | ||
f16cabe4 | 13 | #define NSMAX_KILL_LIMIT 500 |
16cc6e32 | 14 | #define NSMAX_GLINE_LIMIT 500 |
22f7c5c6 | 15 | |
16cc6e32 IB |
16 | /* gline duration, in seconds */ |
17 | #define NSGLINE_DURATION 3600 | |
18 | ||
96429168 | 19 | #define NSMAX_REASON_LEN 120 |
4622c762 | 20 | #define NSMAX_NOTICE_LEN 250 |
a92bb8e1 | 21 | #define NSMAX_COMMAND_LEN 20 |
16cc6e32 | 22 | |
c86edd1d Q |
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 | ||
b697c21c CP |
29 | #define VARIABLE_LEN 10 |
30 | #define MAX_VARIABLES 10 | |
31 | ||
c86edd1d | 32 | struct searchNode; |
c8be5183 | 33 | struct searchCtx; |
b697c21c | 34 | struct coercedata; |
c86edd1d | 35 | |
f33f3f52 | 36 | typedef struct searchNode *(*searchParseFunc)(struct searchCtx *ctx, char *input); |
c8be5183 | 37 | typedef void (*replyFunc)(nick *np, char *format, ...); |
0da2a4ae | 38 | typedef void (*wallFunc)(int level, char *format, ...); |
c8be5183 | 39 | |
f33f3f52 | 40 | typedef struct searchNode *(*parseFunc)(struct searchCtx *, int, char **); |
b697c21c CP |
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 *); | |
0eb4cbd3 | 46 | typedef void (*WhowasDisplayFunc)(struct searchCtx *, nick *, whowas *); |
b697c21c CP |
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 | ||
a92bb8e1 P |
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; | |
e8ff7b61 | 81 | char *help; |
a92bb8e1 P |
82 | struct searchList *next; |
83 | } searchList; | |
84 | ||
c8be5183 CP |
85 | typedef struct searchCtx { |
86 | searchParseFunc parser; | |
87 | replyFunc reply; | |
0da2a4ae | 88 | wallFunc wall; |
0a659cde | 89 | void *arg; |
b697c21c CP |
90 | struct searchVariable vars[MAX_VARIABLES]; |
91 | int lastvar; | |
a92bb8e1 | 92 | struct searchCmd *searchcmd; |
e8ff7b61 | 93 | nick *sender; |
6b2202d0 | 94 | int limit; |
59694aa9 | 95 | array *targets; |
6b2202d0 | 96 | void *displayfn; |
c8be5183 CP |
97 | } searchCtx; |
98 | ||
c86edd1d | 99 | /* Core functions */ |
c7f7a584 | 100 | /* Logical (BOOL -> BOOL)*/ |
f33f3f52 P |
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); | |
c7f7a584 | 104 | |
105 | /* Comparison (INT -> BOOL) */ | |
f33f3f52 P |
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); | |
c7f7a584 | 109 | |
110 | /* String match (STRING -> BOOL) */ | |
f33f3f52 P |
111 | struct searchNode *match_parse(searchCtx *ctx, int argc, char **argv); |
112 | struct searchNode *regex_parse(searchCtx *ctx, int argc, char **argv); | |
c7f7a584 | 113 | |
114 | /* Length (STRING -> INT) */ | |
f33f3f52 | 115 | struct searchNode *length_parse(searchCtx *ctx, int argc, char **argv); |
c7f7a584 | 116 | |
117 | /* kill/gline actions (BOOL) */ | |
f33f3f52 P |
118 | struct searchNode *kill_parse(searchCtx *ctx, int argc, char **argv); |
119 | struct searchNode *gline_parse(searchCtx *ctx, int argc, char **argv); | |
c7f7a584 | 120 | |
4622c762 | 121 | /* notice action (BOOL) */ |
f33f3f52 | 122 | struct searchNode *notice_parse(searchCtx *ctx, int argc, char **argv); |
4622c762 | 123 | |
c7f7a584 | 124 | /* Nick/Channel functions (various types) */ |
f33f3f52 P |
125 | struct searchNode *nick_parse(searchCtx *ctx, int argc, char **argv); |
126 | struct searchNode *modes_parse(searchCtx *ctx, int argc, char **argv); | |
c7f7a584 | 127 | |
128 | /* Nick functions (various types) */ | |
f33f3f52 P |
129 | struct searchNode *hostmask_parse(searchCtx *ctx, int argc, char **argv); |
130 | struct searchNode *realname_parse(searchCtx *ctx, int argc, char **argv); | |
5144ddc4 | 131 | struct searchNode *away_parse(searchCtx *ctx, int argc, char **argv); |
f33f3f52 P |
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); | |
8a959859 | 143 | struct searchNode *cidr_parse(searchCtx *ctx, int argc, char **argv); |
e3b5fea4 | 144 | struct searchNode *ipv6_parse(searchCtx *ctx, int argc, char **argv); |
80e32fcd | 145 | struct searchNode *message_parse(searchCtx *ctx, int argc, char **argv); |
c7f7a584 | 146 | |
0eb4cbd3 GB |
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); | |
8c50d8eb | 153 | struct searchNode *reason_parse(searchCtx *ctx, int argc, char **argv); |
0eb4cbd3 | 154 | |
c7f7a584 | 155 | /* Channel functions (various types) */ |
f33f3f52 P |
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); | |
de8c57b4 C |
162 | struct searchNode *cumodecount_parse(searchCtx *ctx, int argc, char **argv); |
163 | struct searchNode *cumodepct_parse(searchCtx *ctx, int argc, char **argv); | |
f33f3f52 P |
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); | |
c86edd1d | 167 | |
b697c21c | 168 | /* Iteration functions */ |
f33f3f52 P |
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); | |
b697c21c CP |
172 | |
173 | /* Iteraterable functions */ | |
f33f3f52 | 174 | struct searchNode *channeliter_parse(searchCtx *ctx, int argc, char **argv); |
cb857218 | 175 | struct searchNode *nickiter_parse(searchCtx *ctx, int argc, char **argv); |
b697c21c | 176 | |
90334b4c CP |
177 | /* Functions that operate on strings */ |
178 | struct searchNode *cumodes_parse(searchCtx *ctx, int argc, char **argv); | |
179 | ||
c7f7a584 | 180 | /* Force a node to return the thing you want */ |
c8be5183 | 181 | struct searchNode *coerceNode(searchCtx *ctx, struct searchNode *thenode, int type); |
c7f7a584 | 182 | |
c86edd1d | 183 | /* Registration functions */ |
a92bb8e1 P |
184 | searchCmd *registersearchcommand(char *name, int level, CommandHandler cmd, void *defaultdisplayfunc); |
185 | void deregistersearchcommand(searchCmd *scmd); | |
e8ff7b61 | 186 | void registersearchterm(searchCmd *cmd, char *term, parseFunc parsefunc, int level, char *help); |
a92bb8e1 | 187 | void deregistersearchterm(searchCmd *cmd, char *term, parseFunc parsefunc); |
e8ff7b61 P |
188 | |
189 | void registerglobalsearchterm(char *term, parseFunc parsefunc, char *help); | |
a92bb8e1 | 190 | void deregisterglobalsearchterm(char *term, parseFunc parsefunc); |
e8ff7b61 P |
191 | |
192 | void regdisp( searchCmd *cmd, const char *name, void *handler, int level, char *help); | |
a92bb8e1 | 193 | void unregdisp( searchCmd *cmd, const char *name, void *handler); |
c86edd1d | 194 | |
2ba836f2 CP |
195 | /* Special nick* printf */ |
196 | void nssnprintf(char *, size_t, const char *, nick *); | |
197 | ||
e3b5fea4 | 198 | void displaystrerror(replyFunc reply, nick *np, const char *input); |
e3b5fea4 | 199 | |
c86edd1d | 200 | extern const char *parseError; |
b697c21c | 201 | extern nick *senderNSExtern; |
6f8dfee9 | 202 | |
3d2bf13b | 203 | void printnick(searchCtx *, nick *, nick *); |
e8ad630b | 204 | void printuser(searchCtx *, nick *, authname *); |
e1b0e499 | 205 | void printchannel(searchCtx *, nick *, chanindex *); |
0eb4cbd3 | 206 | void printwhowas(searchCtx *, nick *, whowas *); |
6f8dfee9 | 207 | |
6b2202d0 CP |
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); | |
0eb4cbd3 | 211 | void whowassearch_exe(struct searchNode *search, searchCtx *ctx); |
20b9980a CP |
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); | |
e8ad630b | 215 | int do_usersearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); |
0eb4cbd3 | 216 | int do_whowassearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); |
0a659cde CP |
217 | |
218 | void *literal_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); | |
219 | void literal_free(searchCtx *ctx, struct searchNode *thenode); | |
220 | ||
f33f3f52 P |
221 | struct searchVariable *var_register(searchCtx *ctx, char *arg, int type); |
222 | searchNode *var_get(searchCtx *ctx, char *arg); | |
b697c21c CP |
223 | void var_setstr(struct searchVariable *v, char *data); |
224 | ||
59694aa9 | 225 | void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc replyfn, wallFunc wallfn, void *arg, searchCmd *cmd, nick *sender, void *displayfn, int limit, array *targets); |
b697c21c | 226 | |
0a659cde CP |
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 | ||
68d05acb CP |
237 | struct searchASTExpr; |
238 | ||
239 | typedef struct searchASTNode { | |
240 | parseFunc fn; | |
241 | int argc; | |
242 | struct searchASTExpr *argv; | |
243 | } searchASTNode; | |
244 | ||
0a659cde CP |
245 | typedef struct searchASTExpr { |
246 | int type; | |
247 | union { | |
248 | char *literal; | |
68d05acb CP |
249 | /* this was originally a pointer, but having it as one means you can't memcpy directly */ |
250 | struct searchASTNode child; | |
0a659cde | 251 | } u; |
0a659cde CP |
252 | } searchASTExpr; |
253 | ||
e3b5fea4 P |
254 | typedef struct searchASTCache { |
255 | searchASTExpr *tree; | |
256 | searchASTExpr *cache[AST_RECENT]; | |
257 | int nextpos; | |
258 | } searchASTCache; | |
259 | ||
68d05acb CP |
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__})) | |
0a659cde | 267 | |
0a659cde CP |
268 | #define __NSASTChild(...) __NSASTExpr(AST_NODE_CHILD, child, __VA_ARGS__) |
269 | ||
68d05acb | 270 | #define NSASTLiteral(value) __NSASTExpr(AST_NODE_LITERAL, literal, value) |
0a659cde | 271 | #define NSASTNode(fn, ...) __NSASTChild(__NSASTNode(fn, __VA_ARGS__)) |
68d05acb | 272 | #define NSASTManualNode(fn, count, children) __NSASTChild(__NSASTRawNode(fn, count, children)) |
0a659cde | 273 | |
f33f3f52 | 274 | searchNode *search_astparse(searchCtx *, char *); |
0a659cde | 275 | |
59694aa9 GB |
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 *); | |
0a659cde | 280 | |
a92bb8e1 P |
281 | char *ast_printtree(char *buf, size_t bufsize, searchASTExpr *expr, searchCmd *cmd); |
282 | ||
6cb1b086 | 283 | int parseopts(int cargc, char **cargv, int *arg, int *limit, void **subset, void *display, CommandTree *sl, replyFunc reply, void *sender); |
0a659cde | 284 | |
59694aa9 | 285 | typedef int (*ASTFunc)(searchASTExpr *, replyFunc, void *, wallFunc, void *, HeaderFunc, void *, int limit, array *targets); |
68d05acb | 286 | |
0a659cde | 287 | /* erk */ |
a92bb8e1 P |
288 | extern searchList *globalterms; |
289 | ||
290 | extern searchCmd *reg_nicksearch; | |
291 | extern searchCmd *reg_chansearch; | |
292 | extern searchCmd *reg_usersearch; | |
0eb4cbd3 | 293 | extern searchCmd *reg_whowassearch; |
0a659cde | 294 | |
55dd7529 CP |
295 | extern UserDisplayFunc defaultuserfn; |
296 | extern NickDisplayFunc defaultnickfn; | |
297 | extern ChanDisplayFunc defaultchanfn; | |
0eb4cbd3 | 298 | extern WhowasDisplayFunc defaultwhowasfn; |
55dd7529 | 299 | |
31686847 CP |
300 | struct searchNode *argtoconststr(char *command, searchCtx *ctx, char *arg, char **p); |
301 | ||
1188d606 | 302 | #endif |