]>
Commit | Line | Data |
---|---|---|
16cc6e32 | 1 | #include "../nick/nick.h" |
56a84a81 IB |
2 | #include "../parser/parser.h" |
3 | #include "../channel/channel.h" | |
4 | #include "../lib/flags.h" | |
e8ad630b | 5 | #include "../authext/authext.h" |
c86edd1d Q |
6 | |
7 | #define SEARCHTYPE_CHANNEL 1 | |
8 | #define SEARCHTYPE_NICK 2 | |
e8ad630b | 9 | #define SEARCHTYPE_USER 3 |
c86edd1d Q |
10 | |
11 | ||
f16cabe4 | 12 | #define NSMAX_KILL_LIMIT 500 |
16cc6e32 IB |
13 | #define NSMAX_GLINE_LIMIT 500 |
14 | ||
15 | ||
22f7c5c6 IB |
16 | #define NSMAX_GLINE_CLONES 5 |
17 | ||
18 | ||
16cc6e32 IB |
19 | /* gline duration, in seconds */ |
20 | #define NSGLINE_DURATION 3600 | |
21 | ||
96429168 | 22 | #define NSMAX_REASON_LEN 120 |
4622c762 | 23 | #define NSMAX_NOTICE_LEN 250 |
96429168 | 24 | |
16cc6e32 | 25 | |
c86edd1d Q |
26 | #define RETURNTYPE_BOOL 0x01 |
27 | #define RETURNTYPE_INT 0x02 | |
28 | #define RETURNTYPE_STRING 0x03 | |
29 | #define RETURNTYPE_TYPE 0xFF | |
30 | #define RETURNTYPE_CONST 0x100 | |
31 | ||
b697c21c CP |
32 | #define VARIABLE_LEN 10 |
33 | #define MAX_VARIABLES 10 | |
34 | ||
c86edd1d | 35 | struct searchNode; |
c8be5183 | 36 | struct searchCtx; |
b697c21c | 37 | struct coercedata; |
c86edd1d | 38 | |
c8be5183 CP |
39 | typedef struct searchNode *(*searchParseFunc)(struct searchCtx *ctx, int type, char *input); |
40 | typedef void (*replyFunc)(nick *np, char *format, ...); | |
0da2a4ae | 41 | typedef void (*wallFunc)(int level, char *format, ...); |
c8be5183 | 42 | |
b697c21c CP |
43 | typedef struct searchNode *(*parseFunc)(struct searchCtx *, int, int, char **); |
44 | typedef void (*freeFunc)(struct searchCtx *, struct searchNode *); | |
45 | typedef void *(*exeFunc)(struct searchCtx *, struct searchNode *, void *); | |
46 | typedef void (*ChanDisplayFunc)(struct searchCtx *, nick *, chanindex *); | |
47 | typedef void (*NickDisplayFunc)(struct searchCtx *, nick *, nick *); | |
48 | typedef void (*UserDisplayFunc)(struct searchCtx *, nick *, authname *); | |
49 | typedef void (*HeaderFunc)(void *sender, void *arg); | |
50 | ||
51 | struct coercedata { | |
52 | struct searchNode *child; | |
53 | union { | |
54 | char *stringbuf; | |
55 | unsigned long val; | |
56 | } u; | |
57 | }; | |
58 | ||
59 | typedef struct searchNode { | |
60 | int returntype; | |
61 | exeFunc exe; | |
62 | freeFunc free; | |
63 | void *localdata; | |
64 | } searchNode; | |
65 | ||
66 | struct searchVariable { | |
67 | char name[VARIABLE_LEN]; | |
68 | struct searchNode data; | |
69 | struct coercedata cdata; | |
70 | }; | |
71 | ||
c8be5183 CP |
72 | typedef struct searchCtx { |
73 | searchParseFunc parser; | |
74 | replyFunc reply; | |
0da2a4ae | 75 | wallFunc wall; |
0a659cde | 76 | void *arg; |
b697c21c CP |
77 | struct searchVariable vars[MAX_VARIABLES]; |
78 | int lastvar; | |
c8be5183 CP |
79 | } searchCtx; |
80 | ||
c86edd1d | 81 | /* Core functions */ |
c7f7a584 | 82 | /* Logical (BOOL -> BOOL)*/ |
c8be5183 CP |
83 | struct searchNode *and_parse(searchCtx *ctx, int type, int argc, char **argv); |
84 | struct searchNode *not_parse(searchCtx *ctx, int type, int argc, char **argv); | |
85 | struct searchNode *or_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c7f7a584 | 86 | |
87 | /* Comparison (INT -> BOOL) */ | |
c8be5183 CP |
88 | struct searchNode *eq_parse(searchCtx *ctx, int type, int argc, char **argv); |
89 | struct searchNode *lt_parse(searchCtx *ctx, int type, int argc, char **argv); | |
90 | struct searchNode *gt_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c7f7a584 | 91 | |
92 | /* String match (STRING -> BOOL) */ | |
c8be5183 CP |
93 | struct searchNode *match_parse(searchCtx *ctx, int type, int argc, char **argv); |
94 | struct searchNode *regex_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c7f7a584 | 95 | |
96 | /* Length (STRING -> INT) */ | |
c8be5183 | 97 | struct searchNode *length_parse(searchCtx *ctx, int type, int argc, char **argv); |
c7f7a584 | 98 | |
99 | /* kill/gline actions (BOOL) */ | |
c8be5183 CP |
100 | struct searchNode *kill_parse(searchCtx *ctx, int type, int argc, char **argv); |
101 | struct searchNode *gline_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c7f7a584 | 102 | |
4622c762 | 103 | /* notice action (BOOL) */ |
c8be5183 | 104 | struct searchNode *notice_parse(searchCtx *ctx, int type, int argc, char **argv); |
4622c762 | 105 | |
c7f7a584 | 106 | /* Nick/Channel functions (various types) */ |
c8be5183 CP |
107 | struct searchNode *nick_parse(searchCtx *ctx, int type, int argc, char **argv); |
108 | struct searchNode *modes_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c7f7a584 | 109 | |
110 | /* Nick functions (various types) */ | |
c8be5183 CP |
111 | struct searchNode *hostmask_parse(searchCtx *ctx, int type, int argc, char **argv); |
112 | struct searchNode *realname_parse(searchCtx *ctx, int type, int argc, char **argv); | |
113 | struct searchNode *authname_parse(searchCtx *ctx, int type, int argc, char **argv); | |
114 | struct searchNode *authts_parse(searchCtx *ctx, int type, int argc, char **argv); | |
115 | struct searchNode *ident_parse(searchCtx *ctx, int type, int argc, char **argv); | |
116 | struct searchNode *host_parse(searchCtx *ctx, int type, int argc, char **argv); | |
117 | struct searchNode *channel_parse(searchCtx *ctx, int type, int argc, char **argv); | |
118 | struct searchNode *timestamp_parse(searchCtx *ctx, int type, int argc, char **argv); | |
119 | struct searchNode *country_parse(searchCtx *ctx, int type, int argc, char **argv); | |
120 | struct searchNode *ip_parse(searchCtx *ctx, int type, int argc, char **argv); | |
121 | struct searchNode *channels_parse(searchCtx *ctx, int type, int argc, char **argv); | |
122 | struct searchNode *server_parse(searchCtx *ctx, int type, int argc, char **argv); | |
123 | struct searchNode *authid_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c7f7a584 | 124 | |
125 | /* Channel functions (various types) */ | |
c8be5183 CP |
126 | struct searchNode *exists_parse(searchCtx *ctx, int type, int argc, char **argv); |
127 | struct searchNode *services_parse(searchCtx *ctx, int type, int argc, char **argv); | |
128 | struct searchNode *size_parse(searchCtx *ctx, int type, int argc, char **argv); | |
129 | struct searchNode *name_parse(searchCtx *ctx, int type, int argc, char **argv); | |
130 | struct searchNode *topic_parse(searchCtx *ctx, int type, int argc, char **argv); | |
131 | struct searchNode *oppct_parse(searchCtx *ctx, int type, int argc, char **argv); | |
132 | struct searchNode *hostpct_parse(searchCtx *ctx, int type, int argc, char **argv); | |
133 | struct searchNode *authedpct_parse(searchCtx *ctx, int type, int argc, char **argv); | |
134 | struct searchNode *kick_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c86edd1d | 135 | |
c7f7a584 | 136 | /* Interpret a string to give a node */ |
c8be5183 | 137 | struct searchNode *search_parse(searchCtx *ctx, int type, char *input); |
c86edd1d | 138 | |
b697c21c CP |
139 | /* Iteration functions */ |
140 | struct searchNode *any_parse(searchCtx *ctx, int type, int argc, char **argv); | |
141 | struct searchNode *all_parse(searchCtx *ctx, int type, int argc, char **argv); | |
142 | struct searchNode *var_parse(searchCtx *ctx, int type, int argc, char **argv); | |
143 | ||
144 | /* Iteraterable functions */ | |
145 | struct searchNode *channeliter_parse(searchCtx *ctx, int type, int argc, char **argv); | |
146 | ||
c7f7a584 | 147 | /* Force a node to return the thing you want */ |
c8be5183 | 148 | struct searchNode *coerceNode(searchCtx *ctx, struct searchNode *thenode, int type); |
c7f7a584 | 149 | |
c86edd1d Q |
150 | /* Registration functions */ |
151 | void registersearchterm(char *term, parseFunc parsefunc); | |
152 | void deregistersearchterm(char *term, parseFunc parsefunc); | |
73cfc302 | 153 | void regchandisp(const char *name, ChanDisplayFunc handler); |
154 | void unregchandisp(const char *name, ChanDisplayFunc handler); | |
155 | void regnickdisp(const char *name, NickDisplayFunc handler); | |
156 | void unregnickdisp(const char *name, NickDisplayFunc handler); | |
55dd7529 CP |
157 | void reguserdisp(const char *name, UserDisplayFunc handler); |
158 | void unreguserdisp(const char *name, UserDisplayFunc handler); | |
c86edd1d | 159 | |
2ba836f2 CP |
160 | /* Special nick* printf */ |
161 | void nssnprintf(char *, size_t, const char *, nick *); | |
162 | ||
c86edd1d | 163 | extern const char *parseError; |
b697c21c | 164 | extern nick *senderNSExtern; |
6f8dfee9 | 165 | |
3d2bf13b | 166 | void printnick(searchCtx *, nick *, nick *); |
e8ad630b | 167 | void printuser(searchCtx *, nick *, authname *); |
6f8dfee9 | 168 | |
c8be5183 CP |
169 | void nicksearch_exe(struct searchNode *search, searchCtx *sctx, nick *sender, NickDisplayFunc display, int limit); |
170 | void chansearch_exe(struct searchNode *search, searchCtx *sctx, nick *sender, ChanDisplayFunc display, int limit); | |
e8ad630b | 171 | void usersearch_exe(struct searchNode *search, searchCtx *ctx, nick *sender, UserDisplayFunc display, int limit); |
20b9980a CP |
172 | |
173 | int do_nicksearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); | |
174 | int do_chansearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); | |
e8ad630b | 175 | int do_usersearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); |
0a659cde CP |
176 | |
177 | void *literal_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); | |
178 | void literal_free(searchCtx *ctx, struct searchNode *thenode); | |
179 | ||
b697c21c CP |
180 | struct searchVariable *var_register(searchCtx *ctx, int nstype, char *arg, int type); |
181 | searchNode *var_get(searchCtx *ctx, int nstype, char *arg); | |
182 | void var_setstr(struct searchVariable *v, char *data); | |
183 | ||
184 | void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc replyfn, wallFunc wallfn, void *arg); | |
185 | ||
0a659cde CP |
186 | /* AST functions */ |
187 | ||
188 | struct searchASTNode; | |
189 | ||
190 | #define AST_NODE_CHILD 1 | |
191 | #define AST_NODE_LITERAL 2 | |
192 | ||
193 | /* items to store in the ast lookup cache */ | |
194 | #define AST_RECENT 10 | |
195 | ||
196 | typedef struct searchASTExpr { | |
197 | int type; | |
198 | union { | |
199 | char *literal; | |
200 | struct searchASTNode *child; | |
201 | } u; | |
0a659cde CP |
202 | } searchASTExpr; |
203 | ||
204 | typedef struct searchASTNode { | |
205 | parseFunc fn; | |
206 | int argc; | |
207 | struct searchASTExpr **argv; | |
208 | } searchASTNode; | |
209 | ||
210 | /* | |
211 | * | |
212 | * FEAR THE COMPOUND LITERALS | |
213 | * MUHAHAHHAHAHAHAHAHAAH | |
214 | * | |
215 | */ | |
012fa9be | 216 | #define __NSASTExpr(x, y, ...) &(searchASTExpr){.type = x, .u.y = __VA_ARGS__} |
0a659cde CP |
217 | #define __NSASTList(...) (searchASTExpr *[]){__VA_ARGS__} |
218 | #define __NSASTNode(x, ...) &(searchASTNode){.fn = x, .argc = sizeof(__NSASTList(__VA_ARGS__)) / sizeof(__NSASTList(__VA_ARGS__)[0]), .argv = __NSASTList(__VA_ARGS__)} | |
219 | #define __NSASTChild(...) __NSASTExpr(AST_NODE_CHILD, child, __VA_ARGS__) | |
220 | ||
221 | #define NSASTLiteral(data) __NSASTExpr(AST_NODE_LITERAL, literal, data) | |
222 | #define NSASTNode(fn, ...) __NSASTChild(__NSASTNode(fn, __VA_ARGS__)) | |
223 | ||
224 | searchNode *search_astparse(searchCtx *, int, char *); | |
225 | ||
2181a10f CP |
226 | int ast_nicksearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, NickDisplayFunc display, HeaderFunc header, void *headerarg, int limit); |
227 | int ast_chansearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, ChanDisplayFunc display, HeaderFunc header, void *headerarg, int limit); | |
228 | int ast_usersearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, UserDisplayFunc display, HeaderFunc header, void *headerarg, int limit); | |
0a659cde CP |
229 | |
230 | char *ast_printtree(char *buf, size_t bufsize, searchASTExpr *expr); | |
231 | ||
232 | /* erk */ | |
233 | extern CommandTree *searchTree; | |
234 | ||
55dd7529 CP |
235 | extern UserDisplayFunc defaultuserfn; |
236 | extern NickDisplayFunc defaultnickfn; | |
237 | extern ChanDisplayFunc defaultchanfn; | |
238 |