]>
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 | |
f33f3f52 | 39 | typedef struct searchNode *(*searchParseFunc)(struct searchCtx *ctx, char *input); |
c8be5183 | 40 | typedef void (*replyFunc)(nick *np, char *format, ...); |
0da2a4ae | 41 | typedef void (*wallFunc)(int level, char *format, ...); |
c8be5183 | 42 | |
f33f3f52 | 43 | typedef struct searchNode *(*parseFunc)(struct searchCtx *, int, char **); |
b697c21c CP |
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; | |
f33f3f52 | 79 | int type; |
c8be5183 CP |
80 | } searchCtx; |
81 | ||
c86edd1d | 82 | /* Core functions */ |
c7f7a584 | 83 | /* Logical (BOOL -> BOOL)*/ |
f33f3f52 P |
84 | struct searchNode *and_parse(searchCtx *ctx, int argc, char **argv); |
85 | struct searchNode *not_parse(searchCtx *ctx, int argc, char **argv); | |
86 | struct searchNode *or_parse(searchCtx *ctx, int argc, char **argv); | |
c7f7a584 | 87 | |
88 | /* Comparison (INT -> BOOL) */ | |
f33f3f52 P |
89 | struct searchNode *eq_parse(searchCtx *ctx, int argc, char **argv); |
90 | struct searchNode *lt_parse(searchCtx *ctx, int argc, char **argv); | |
91 | struct searchNode *gt_parse(searchCtx *ctx, int argc, char **argv); | |
c7f7a584 | 92 | |
93 | /* String match (STRING -> BOOL) */ | |
f33f3f52 P |
94 | struct searchNode *match_parse(searchCtx *ctx, int argc, char **argv); |
95 | struct searchNode *regex_parse(searchCtx *ctx, int argc, char **argv); | |
c7f7a584 | 96 | |
97 | /* Length (STRING -> INT) */ | |
f33f3f52 | 98 | struct searchNode *length_parse(searchCtx *ctx, int argc, char **argv); |
c7f7a584 | 99 | |
100 | /* kill/gline actions (BOOL) */ | |
f33f3f52 P |
101 | struct searchNode *kill_parse(searchCtx *ctx, int argc, char **argv); |
102 | struct searchNode *gline_parse(searchCtx *ctx, int argc, char **argv); | |
c7f7a584 | 103 | |
4622c762 | 104 | /* notice action (BOOL) */ |
f33f3f52 | 105 | struct searchNode *notice_parse(searchCtx *ctx, int argc, char **argv); |
4622c762 | 106 | |
c7f7a584 | 107 | /* Nick/Channel functions (various types) */ |
f33f3f52 P |
108 | struct searchNode *nick_parse(searchCtx *ctx, int argc, char **argv); |
109 | struct searchNode *modes_parse(searchCtx *ctx, int argc, char **argv); | |
c7f7a584 | 110 | |
111 | /* Nick functions (various types) */ | |
f33f3f52 P |
112 | struct searchNode *hostmask_parse(searchCtx *ctx, int argc, char **argv); |
113 | struct searchNode *realname_parse(searchCtx *ctx, int argc, char **argv); | |
114 | struct searchNode *authname_parse(searchCtx *ctx, int argc, char **argv); | |
115 | struct searchNode *authts_parse(searchCtx *ctx, int argc, char **argv); | |
116 | struct searchNode *ident_parse(searchCtx *ctx, int argc, char **argv); | |
117 | struct searchNode *host_parse(searchCtx *ctx, int argc, char **argv); | |
118 | struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv); | |
119 | struct searchNode *timestamp_parse(searchCtx *ctx, int argc, char **argv); | |
120 | struct searchNode *country_parse(searchCtx *ctx, int argc, char **argv); | |
121 | struct searchNode *ip_parse(searchCtx *ctx, int argc, char **argv); | |
122 | struct searchNode *channels_parse(searchCtx *ctx, int argc, char **argv); | |
123 | struct searchNode *server_parse(searchCtx *ctx, int argc, char **argv); | |
124 | struct searchNode *authid_parse(searchCtx *ctx, int argc, char **argv); | |
c7f7a584 | 125 | |
126 | /* Channel functions (various types) */ | |
f33f3f52 P |
127 | struct searchNode *exists_parse(searchCtx *ctx, int argc, char **argv); |
128 | struct searchNode *services_parse(searchCtx *ctx, int argc, char **argv); | |
129 | struct searchNode *size_parse(searchCtx *ctx, int argc, char **argv); | |
130 | struct searchNode *name_parse(searchCtx *ctx, int argc, char **argv); | |
131 | struct searchNode *topic_parse(searchCtx *ctx, int argc, char **argv); | |
132 | struct searchNode *oppct_parse(searchCtx *ctx, int argc, char **argv); | |
133 | struct searchNode *hostpct_parse(searchCtx *ctx, int argc, char **argv); | |
134 | struct searchNode *authedpct_parse(searchCtx *ctx, int argc, char **argv); | |
135 | struct searchNode *kick_parse(searchCtx *ctx, int argc, char **argv); | |
c86edd1d | 136 | |
c7f7a584 | 137 | /* Interpret a string to give a node */ |
f33f3f52 | 138 | struct searchNode *search_parse(searchCtx *ctx, char *input); |
c86edd1d | 139 | |
b697c21c | 140 | /* Iteration functions */ |
f33f3f52 P |
141 | struct searchNode *any_parse(searchCtx *ctx, int argc, char **argv); |
142 | struct searchNode *all_parse(searchCtx *ctx, int argc, char **argv); | |
143 | struct searchNode *var_parse(searchCtx *ctx, int argc, char **argv); | |
b697c21c CP |
144 | |
145 | /* Iteraterable functions */ | |
f33f3f52 | 146 | struct searchNode *channeliter_parse(searchCtx *ctx, int argc, char **argv); |
b697c21c | 147 | |
c7f7a584 | 148 | /* Force a node to return the thing you want */ |
c8be5183 | 149 | struct searchNode *coerceNode(searchCtx *ctx, struct searchNode *thenode, int type); |
c7f7a584 | 150 | |
c86edd1d Q |
151 | /* Registration functions */ |
152 | void registersearchterm(char *term, parseFunc parsefunc); | |
153 | void deregistersearchterm(char *term, parseFunc parsefunc); | |
73cfc302 | 154 | void regchandisp(const char *name, ChanDisplayFunc handler); |
155 | void unregchandisp(const char *name, ChanDisplayFunc handler); | |
156 | void regnickdisp(const char *name, NickDisplayFunc handler); | |
157 | void unregnickdisp(const char *name, NickDisplayFunc handler); | |
55dd7529 CP |
158 | void reguserdisp(const char *name, UserDisplayFunc handler); |
159 | void unreguserdisp(const char *name, UserDisplayFunc handler); | |
c86edd1d | 160 | |
2ba836f2 CP |
161 | /* Special nick* printf */ |
162 | void nssnprintf(char *, size_t, const char *, nick *); | |
163 | ||
c86edd1d | 164 | extern const char *parseError; |
b697c21c | 165 | extern nick *senderNSExtern; |
6f8dfee9 | 166 | |
3d2bf13b | 167 | void printnick(searchCtx *, nick *, nick *); |
e8ad630b | 168 | void printuser(searchCtx *, nick *, authname *); |
6f8dfee9 | 169 | |
c8be5183 CP |
170 | void nicksearch_exe(struct searchNode *search, searchCtx *sctx, nick *sender, NickDisplayFunc display, int limit); |
171 | void chansearch_exe(struct searchNode *search, searchCtx *sctx, nick *sender, ChanDisplayFunc display, int limit); | |
e8ad630b | 172 | void usersearch_exe(struct searchNode *search, searchCtx *ctx, nick *sender, UserDisplayFunc display, int limit); |
20b9980a CP |
173 | |
174 | int do_nicksearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); | |
175 | int do_chansearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); | |
e8ad630b | 176 | int do_usersearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); |
0a659cde CP |
177 | |
178 | void *literal_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); | |
179 | void literal_free(searchCtx *ctx, struct searchNode *thenode); | |
180 | ||
f33f3f52 P |
181 | struct searchVariable *var_register(searchCtx *ctx, char *arg, int type); |
182 | searchNode *var_get(searchCtx *ctx, char *arg); | |
b697c21c CP |
183 | void var_setstr(struct searchVariable *v, char *data); |
184 | ||
f33f3f52 | 185 | void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc replyfn, wallFunc wallfn, void *arg, int type); |
b697c21c | 186 | |
0a659cde CP |
187 | /* AST functions */ |
188 | ||
189 | struct searchASTNode; | |
190 | ||
191 | #define AST_NODE_CHILD 1 | |
192 | #define AST_NODE_LITERAL 2 | |
193 | ||
194 | /* items to store in the ast lookup cache */ | |
195 | #define AST_RECENT 10 | |
196 | ||
197 | typedef struct searchASTExpr { | |
198 | int type; | |
199 | union { | |
200 | char *literal; | |
201 | struct searchASTNode *child; | |
202 | } u; | |
0a659cde CP |
203 | } searchASTExpr; |
204 | ||
205 | typedef struct searchASTNode { | |
206 | parseFunc fn; | |
207 | int argc; | |
208 | struct searchASTExpr **argv; | |
209 | } searchASTNode; | |
210 | ||
211 | /* | |
212 | * | |
213 | * FEAR THE COMPOUND LITERALS | |
214 | * MUHAHAHHAHAHAHAHAHAAH | |
215 | * | |
216 | */ | |
012fa9be | 217 | #define __NSASTExpr(x, y, ...) &(searchASTExpr){.type = x, .u.y = __VA_ARGS__} |
0a659cde CP |
218 | #define __NSASTList(...) (searchASTExpr *[]){__VA_ARGS__} |
219 | #define __NSASTNode(x, ...) &(searchASTNode){.fn = x, .argc = sizeof(__NSASTList(__VA_ARGS__)) / sizeof(__NSASTList(__VA_ARGS__)[0]), .argv = __NSASTList(__VA_ARGS__)} | |
220 | #define __NSASTChild(...) __NSASTExpr(AST_NODE_CHILD, child, __VA_ARGS__) | |
221 | ||
222 | #define NSASTLiteral(data) __NSASTExpr(AST_NODE_LITERAL, literal, data) | |
223 | #define NSASTNode(fn, ...) __NSASTChild(__NSASTNode(fn, __VA_ARGS__)) | |
224 | ||
f33f3f52 | 225 | searchNode *search_astparse(searchCtx *, char *); |
0a659cde | 226 | |
2181a10f CP |
227 | int ast_nicksearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, NickDisplayFunc display, HeaderFunc header, void *headerarg, int limit); |
228 | int ast_chansearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, ChanDisplayFunc display, HeaderFunc header, void *headerarg, int limit); | |
229 | int ast_usersearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, UserDisplayFunc display, HeaderFunc header, void *headerarg, int limit); | |
0a659cde CP |
230 | |
231 | char *ast_printtree(char *buf, size_t bufsize, searchASTExpr *expr); | |
232 | ||
233 | /* erk */ | |
234 | extern CommandTree *searchTree; | |
235 | ||
55dd7529 CP |
236 | extern UserDisplayFunc defaultuserfn; |
237 | extern NickDisplayFunc defaultnickfn; | |
238 | extern ChanDisplayFunc defaultchanfn; | |
239 |