]>
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 | ||
32 | struct searchNode; | |
c8be5183 | 33 | struct searchCtx; |
c86edd1d | 34 | |
c8be5183 CP |
35 | typedef struct searchNode *(*searchParseFunc)(struct searchCtx *ctx, int type, char *input); |
36 | typedef void (*replyFunc)(nick *np, char *format, ...); | |
0da2a4ae | 37 | typedef void (*wallFunc)(int level, char *format, ...); |
c8be5183 CP |
38 | |
39 | typedef struct searchCtx { | |
40 | searchParseFunc parser; | |
41 | replyFunc reply; | |
0da2a4ae | 42 | wallFunc wall; |
0a659cde | 43 | void *arg; |
c8be5183 CP |
44 | } searchCtx; |
45 | ||
46 | typedef struct searchNode *(*parseFunc)(searchCtx *, int, int, char **); | |
47 | typedef void (*freeFunc)(searchCtx *, struct searchNode *); | |
48 | typedef void *(*exeFunc)(searchCtx *, struct searchNode *, void *); | |
3d2bf13b CP |
49 | typedef void (*ChanDisplayFunc)(searchCtx *, nick *, chanindex *); |
50 | typedef void (*NickDisplayFunc)(searchCtx *, nick *, nick *); | |
e8ad630b | 51 | typedef void (*UserDisplayFunc)(searchCtx *, nick *, authname *); |
2181a10f | 52 | typedef void (*HeaderFunc)(void *sender, void *arg); |
c86edd1d Q |
53 | |
54 | /* Core functions */ | |
c7f7a584 | 55 | /* Logical (BOOL -> BOOL)*/ |
c8be5183 CP |
56 | struct searchNode *and_parse(searchCtx *ctx, int type, int argc, char **argv); |
57 | struct searchNode *not_parse(searchCtx *ctx, int type, int argc, char **argv); | |
58 | struct searchNode *or_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c7f7a584 | 59 | |
60 | /* Comparison (INT -> BOOL) */ | |
c8be5183 CP |
61 | struct searchNode *eq_parse(searchCtx *ctx, int type, int argc, char **argv); |
62 | struct searchNode *lt_parse(searchCtx *ctx, int type, int argc, char **argv); | |
63 | struct searchNode *gt_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c7f7a584 | 64 | |
65 | /* String match (STRING -> BOOL) */ | |
c8be5183 CP |
66 | struct searchNode *match_parse(searchCtx *ctx, int type, int argc, char **argv); |
67 | struct searchNode *regex_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c7f7a584 | 68 | |
69 | /* Length (STRING -> INT) */ | |
c8be5183 | 70 | struct searchNode *length_parse(searchCtx *ctx, int type, int argc, char **argv); |
c7f7a584 | 71 | |
72 | /* kill/gline actions (BOOL) */ | |
c8be5183 CP |
73 | struct searchNode *kill_parse(searchCtx *ctx, int type, int argc, char **argv); |
74 | struct searchNode *gline_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c7f7a584 | 75 | |
4622c762 | 76 | /* notice action (BOOL) */ |
c8be5183 | 77 | struct searchNode *notice_parse(searchCtx *ctx, int type, int argc, char **argv); |
4622c762 | 78 | |
c7f7a584 | 79 | /* Nick/Channel functions (various types) */ |
c8be5183 CP |
80 | struct searchNode *nick_parse(searchCtx *ctx, int type, int argc, char **argv); |
81 | struct searchNode *modes_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c7f7a584 | 82 | |
83 | /* Nick functions (various types) */ | |
c8be5183 CP |
84 | struct searchNode *hostmask_parse(searchCtx *ctx, int type, int argc, char **argv); |
85 | struct searchNode *realname_parse(searchCtx *ctx, int type, int argc, char **argv); | |
86 | struct searchNode *authname_parse(searchCtx *ctx, int type, int argc, char **argv); | |
87 | struct searchNode *authts_parse(searchCtx *ctx, int type, int argc, char **argv); | |
88 | struct searchNode *ident_parse(searchCtx *ctx, int type, int argc, char **argv); | |
89 | struct searchNode *host_parse(searchCtx *ctx, int type, int argc, char **argv); | |
90 | struct searchNode *channel_parse(searchCtx *ctx, int type, int argc, char **argv); | |
91 | struct searchNode *timestamp_parse(searchCtx *ctx, int type, int argc, char **argv); | |
92 | struct searchNode *country_parse(searchCtx *ctx, int type, int argc, char **argv); | |
93 | struct searchNode *ip_parse(searchCtx *ctx, int type, int argc, char **argv); | |
94 | struct searchNode *channels_parse(searchCtx *ctx, int type, int argc, char **argv); | |
95 | struct searchNode *server_parse(searchCtx *ctx, int type, int argc, char **argv); | |
96 | struct searchNode *authid_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c7f7a584 | 97 | |
98 | /* Channel functions (various types) */ | |
c8be5183 CP |
99 | struct searchNode *exists_parse(searchCtx *ctx, int type, int argc, char **argv); |
100 | struct searchNode *services_parse(searchCtx *ctx, int type, int argc, char **argv); | |
101 | struct searchNode *size_parse(searchCtx *ctx, int type, int argc, char **argv); | |
102 | struct searchNode *name_parse(searchCtx *ctx, int type, int argc, char **argv); | |
103 | struct searchNode *topic_parse(searchCtx *ctx, int type, int argc, char **argv); | |
104 | struct searchNode *oppct_parse(searchCtx *ctx, int type, int argc, char **argv); | |
105 | struct searchNode *hostpct_parse(searchCtx *ctx, int type, int argc, char **argv); | |
106 | struct searchNode *authedpct_parse(searchCtx *ctx, int type, int argc, char **argv); | |
107 | struct searchNode *kick_parse(searchCtx *ctx, int type, int argc, char **argv); | |
c86edd1d | 108 | |
c7f7a584 | 109 | /* Interpret a string to give a node */ |
c8be5183 | 110 | struct searchNode *search_parse(searchCtx *ctx, int type, char *input); |
c86edd1d | 111 | |
c7f7a584 | 112 | /* Force a node to return the thing you want */ |
c8be5183 | 113 | struct searchNode *coerceNode(searchCtx *ctx, struct searchNode *thenode, int type); |
c7f7a584 | 114 | |
c86edd1d Q |
115 | /* Registration functions */ |
116 | void registersearchterm(char *term, parseFunc parsefunc); | |
117 | void deregistersearchterm(char *term, parseFunc parsefunc); | |
73cfc302 | 118 | void regchandisp(const char *name, ChanDisplayFunc handler); |
119 | void unregchandisp(const char *name, ChanDisplayFunc handler); | |
120 | void regnickdisp(const char *name, NickDisplayFunc handler); | |
121 | void unregnickdisp(const char *name, NickDisplayFunc handler); | |
55dd7529 CP |
122 | void reguserdisp(const char *name, UserDisplayFunc handler); |
123 | void unreguserdisp(const char *name, UserDisplayFunc handler); | |
c86edd1d | 124 | |
2ba836f2 CP |
125 | /* Special nick* printf */ |
126 | void nssnprintf(char *, size_t, const char *, nick *); | |
127 | ||
c86edd1d Q |
128 | typedef struct searchNode { |
129 | int returntype; | |
130 | exeFunc exe; | |
131 | freeFunc free; | |
132 | void *localdata; | |
133 | } searchNode; | |
134 | ||
135 | extern const char *parseError; | |
6f8dfee9 | 136 | |
3d2bf13b | 137 | void printnick(searchCtx *, nick *, nick *); |
e8ad630b | 138 | void printuser(searchCtx *, nick *, authname *); |
6f8dfee9 | 139 | |
c8be5183 CP |
140 | void nicksearch_exe(struct searchNode *search, searchCtx *sctx, nick *sender, NickDisplayFunc display, int limit); |
141 | void chansearch_exe(struct searchNode *search, searchCtx *sctx, nick *sender, ChanDisplayFunc display, int limit); | |
e8ad630b | 142 | void usersearch_exe(struct searchNode *search, searchCtx *ctx, nick *sender, UserDisplayFunc display, int limit); |
20b9980a CP |
143 | |
144 | int do_nicksearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); | |
145 | int do_chansearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); | |
e8ad630b | 146 | int do_usersearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv); |
0a659cde CP |
147 | |
148 | void *literal_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); | |
149 | void literal_free(searchCtx *ctx, struct searchNode *thenode); | |
150 | ||
151 | /* AST functions */ | |
152 | ||
153 | struct searchASTNode; | |
154 | ||
155 | #define AST_NODE_CHILD 1 | |
156 | #define AST_NODE_LITERAL 2 | |
157 | ||
158 | /* items to store in the ast lookup cache */ | |
159 | #define AST_RECENT 10 | |
160 | ||
161 | typedef struct searchASTExpr { | |
162 | int type; | |
163 | union { | |
164 | char *literal; | |
165 | struct searchASTNode *child; | |
166 | } u; | |
0a659cde CP |
167 | } searchASTExpr; |
168 | ||
169 | typedef struct searchASTNode { | |
170 | parseFunc fn; | |
171 | int argc; | |
172 | struct searchASTExpr **argv; | |
173 | } searchASTNode; | |
174 | ||
175 | /* | |
176 | * | |
177 | * FEAR THE COMPOUND LITERALS | |
178 | * MUHAHAHHAHAHAHAHAHAAH | |
179 | * | |
180 | */ | |
012fa9be | 181 | #define __NSASTExpr(x, y, ...) &(searchASTExpr){.type = x, .u.y = __VA_ARGS__} |
0a659cde CP |
182 | #define __NSASTList(...) (searchASTExpr *[]){__VA_ARGS__} |
183 | #define __NSASTNode(x, ...) &(searchASTNode){.fn = x, .argc = sizeof(__NSASTList(__VA_ARGS__)) / sizeof(__NSASTList(__VA_ARGS__)[0]), .argv = __NSASTList(__VA_ARGS__)} | |
184 | #define __NSASTChild(...) __NSASTExpr(AST_NODE_CHILD, child, __VA_ARGS__) | |
185 | ||
186 | #define NSASTLiteral(data) __NSASTExpr(AST_NODE_LITERAL, literal, data) | |
187 | #define NSASTNode(fn, ...) __NSASTChild(__NSASTNode(fn, __VA_ARGS__)) | |
188 | ||
189 | searchNode *search_astparse(searchCtx *, int, char *); | |
190 | ||
2181a10f CP |
191 | int ast_nicksearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, NickDisplayFunc display, HeaderFunc header, void *headerarg, int limit); |
192 | int ast_chansearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, ChanDisplayFunc display, HeaderFunc header, void *headerarg, int limit); | |
193 | int ast_usersearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, UserDisplayFunc display, HeaderFunc header, void *headerarg, int limit); | |
0a659cde CP |
194 | |
195 | char *ast_printtree(char *buf, size_t bufsize, searchASTExpr *expr); | |
196 | ||
197 | /* erk */ | |
198 | extern CommandTree *searchTree; | |
199 | ||
55dd7529 CP |
200 | extern UserDisplayFunc defaultuserfn; |
201 | extern NickDisplayFunc defaultnickfn; | |
202 | extern ChanDisplayFunc defaultchanfn; | |
203 |